From b6eeb275a30ac34feb1d651144e49edbdde7de26 Mon Sep 17 00:00:00 2001 From: Elyon Date: Mon, 9 Aug 2021 13:39:38 -0700 Subject: [PATCH 01/25] simplifying setupStore --- osmosis/src/setupStore.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osmosis/src/setupStore.js b/osmosis/src/setupStore.js index ce17a8e..d450a37 100644 --- a/osmosis/src/setupStore.js +++ b/osmosis/src/setupStore.js @@ -25,7 +25,8 @@ const setupStore = useCustomHook => { ); }; - + storeRef.Context = StoreContext; + storeRef.Provider = withStoreContext; return [StoreContext, withStoreContext, storeRef]; }; From c4557cec1dc9ee0d5c4bfd57aa199dfb36d14c4c Mon Sep 17 00:00:00 2001 From: Elyon Date: Mon, 9 Aug 2021 13:50:29 -0700 Subject: [PATCH 02/25] returning just storeRef --- osmosis/src/setupStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osmosis/src/setupStore.js b/osmosis/src/setupStore.js index d450a37..ec51990 100644 --- a/osmosis/src/setupStore.js +++ b/osmosis/src/setupStore.js @@ -27,7 +27,7 @@ const setupStore = useCustomHook => { }; storeRef.Context = StoreContext; storeRef.Provider = withStoreContext; - return [StoreContext, withStoreContext, storeRef]; + return [ storeRef ]; }; export { setupStore }; From 4ed00b063073032c1fb8c687056239c8866f3f01 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 9 Aug 2021 16:37:41 -0500 Subject: [PATCH 03/25] Bump tar from 6.1.0 to 6.1.5 in /examples/counter-react (#68) Bumps [tar](https://github.com/npm/node-tar) from 6.1.0 to 6.1.5. - [Release notes](https://github.com/npm/node-tar/releases) - [Changelog](https://github.com/npm/node-tar/blob/main/CHANGELOG.md) - [Commits](https://github.com/npm/node-tar/compare/v6.1.0...v6.1.5) --- updated-dependencies: - dependency-name: tar dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- examples/counter-react/yarn.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/counter-react/yarn.lock b/examples/counter-react/yarn.lock index 7e5146a..d660380 100644 --- a/examples/counter-react/yarn.lock +++ b/examples/counter-react/yarn.lock @@ -1502,7 +1502,7 @@ integrity sha512-DetpxZw1fzPD5xUBrIAoplLChO2VB8DlL5Gg+I1IR9b2wPqYIca2WSUxL5g1vLeR4MsQq1NeWriXAVffV+U1Fw== "@shipt/osmosis@../../osmosis": - version "1.1.0" + version "1.1.1" "@sinonjs/commons@^1.7.0": version "1.8.2" @@ -10494,9 +10494,9 @@ tapable@^1.0.0, tapable@^1.1.3: integrity sha512-4WK/bYZmj8xLr+HUCODHGF1ZFzsYffasLUgEiMBY4fgtltdO6B4WJtlSbPaDTLpYTcGVwM2qLnFTICEcNxs3kA== tar@^6.0.2: - version "6.1.0" - resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.0.tgz#d1724e9bcc04b977b18d5c573b333a2207229a83" - integrity sha512-DUCttfhsnLCjwoDoFcI+B2iJgYa93vBnDUATYEeRx6sntCTdN01VnqsIuTlALXla/LWooNg0yEGeB+Y8WdFxGA== + version "6.1.5" + resolved "https://registry.yarnpkg.com/tar/-/tar-6.1.5.tgz#6e25bee1cfda94317aedc3f5d49290ae68361d73" + integrity sha512-FiK6MQyyaqd5vHuUjbg/NpO8BuEGeSXcmlH7Pt/JkugWS8s0w8nKybWjHDJiwzCAIKZ66uof4ghm4tBADjcqRA== dependencies: chownr "^2.0.0" fs-minipass "^2.0.0" From 57ee8a0b4285a912abcc0b061054d3fe4a522731 Mon Sep 17 00:00:00 2001 From: Elyon Date: Mon, 9 Aug 2021 14:47:15 -0700 Subject: [PATCH 04/25] returning single object, instead of array --- osmosis/src/setupStore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osmosis/src/setupStore.js b/osmosis/src/setupStore.js index ec51990..2c09ed6 100644 --- a/osmosis/src/setupStore.js +++ b/osmosis/src/setupStore.js @@ -27,7 +27,7 @@ const setupStore = useCustomHook => { }; storeRef.Context = StoreContext; storeRef.Provider = withStoreContext; - return [ storeRef ]; + return storeRef; }; export { setupStore }; From 5681908284bca637d53efcccf42fc6085710ca07 Mon Sep 17 00:00:00 2001 From: Elyon Olaniran Date: Tue, 10 Aug 2021 08:10:32 -0700 Subject: [PATCH 05/25] Update CODEOWNERS (#69) --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 1beb482..937ab2d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1 +1 @@ -* @chaceburnette @lein-haz @joshuakg @jkhusanov @divijadesai @taylorcore @MarquessV @TomMahle +* @chaceburnette @lein-haz @joshuakg @jkhusanov @divijadesai @taylorcore @MarquessV @TomMahle @ChiefoftheOwls From 5648429720607f0253f97bac5a520917a3594e32 Mon Sep 17 00:00:00 2001 From: Elyon Date: Wed, 11 Aug 2021 15:10:55 -0700 Subject: [PATCH 06/25] updating tests in example project --- examples/counter-react/src/App.js | 4 ++-- examples/counter-react/src/__tests__/counter.spec.js | 6 +++--- examples/counter-react/src/counter.js | 4 ++-- examples/counter-react/src/dispatchCounter.js | 6 +++--- .../counter-react/src/store/__tests__/counter.store.spec.js | 6 +++--- examples/counter-react/src/store/counter.store.js | 4 ++-- .../counter-react/src/store/counterWithReducer.store.js | 4 ++-- osmosis/src/setupStore.js | 5 +++++ yarn.lock | 4 ++++ 9 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 yarn.lock diff --git a/examples/counter-react/src/App.js b/examples/counter-react/src/App.js index ee5b394..996a4cf 100644 --- a/examples/counter-react/src/App.js +++ b/examples/counter-react/src/App.js @@ -1,5 +1,5 @@ import { StoreProvider, configureUsePersistedState } from '@shipt/osmosis'; -import { CounterWrapper, CounterWithReducerWrapper } from './store'; +import { counterRef, CounterWithReducerWrapper } from './store'; import Counter from './counter'; import PersistedCounter from './persistedCounter.js'; @@ -20,4 +20,4 @@ const App = () => { ); }; -export default StoreProvider([CounterWrapper, CounterWithReducerWrapper], App); +export default StoreProvider([counterRef.Provider, CounterWithReducerWrapper], App); diff --git a/examples/counter-react/src/__tests__/counter.spec.js b/examples/counter-react/src/__tests__/counter.spec.js index 5b6e7ff..1ac11be 100644 --- a/examples/counter-react/src/__tests__/counter.spec.js +++ b/examples/counter-react/src/__tests__/counter.spec.js @@ -1,6 +1,6 @@ import React from 'react'; import Counter from '../counter'; -import { CounterContext } from '../store'; +import { counterRef } from '../store'; import { render, fireEvent } from '@testing-library/react'; describe('Counter', () => { @@ -12,9 +12,9 @@ describe('Counter', () => { decrementCount: jest.fn() }; let ContextComponent = () => ( - + - + ); it('renders default', async () => { let wrapper = await render(); diff --git a/examples/counter-react/src/counter.js b/examples/counter-react/src/counter.js index 58731dc..27d7892 100644 --- a/examples/counter-react/src/counter.js +++ b/examples/counter-react/src/counter.js @@ -1,8 +1,8 @@ import React, { useContext } from 'react'; -import { CounterContext } from './store'; +import { counterRef } from './store'; const Counter = () => { - const [counterContext] = useContext(CounterContext); + const [counterContext] = useContext(counterRef.Context); let { count } = counterContext.state; return ( diff --git a/examples/counter-react/src/dispatchCounter.js b/examples/counter-react/src/dispatchCounter.js index 2da7efa..53940a3 100644 --- a/examples/counter-react/src/dispatchCounter.js +++ b/examples/counter-react/src/dispatchCounter.js @@ -1,8 +1,8 @@ import React, { useContext } from 'react'; -import { CounterWithReducerContext } from './store'; +import { counterWithReducerRef } from './store'; const PersistedCounter = () => { - const [counterContext] = useContext(CounterWithReducerContext); + const [counterContext] = useContext(counterWithReducerRef.Context); let { dispatch, counterState: { count }} = counterContext; return ( @@ -18,4 +18,4 @@ const PersistedCounter = () => { ); }; -export default PersistedCounter; +export default PersistedCounter; \ No newline at end of file diff --git a/examples/counter-react/src/store/__tests__/counter.store.spec.js b/examples/counter-react/src/store/__tests__/counter.store.spec.js index 4437f4d..0925230 100644 --- a/examples/counter-react/src/store/__tests__/counter.store.spec.js +++ b/examples/counter-react/src/store/__tests__/counter.store.spec.js @@ -1,13 +1,13 @@ import React, { useContext } from 'react'; -import { CounterContext, CounterWrapper} from '../counter.store'; +import { counterRef } from '../counter.store'; import { render } from '@testing-library/react'; import { act } from 'react-dom/test-utils'; describe('CounterStore', () => { let store; const renderStore = () => { - let Prep = CounterWrapper(() => { - store = useContext(CounterContext)[0]; + let Prep = counterRef.Provider(() => { + store = useContext(counterRef.Context)[0]; return null; }); render(); diff --git a/examples/counter-react/src/store/counter.store.js b/examples/counter-react/src/store/counter.store.js index ad060e6..396b605 100644 --- a/examples/counter-react/src/store/counter.store.js +++ b/examples/counter-react/src/store/counter.store.js @@ -25,6 +25,6 @@ const useCounterContainer = () => { }; }; -let [CounterContext, CounterWrapper, counterRef] = setupStore(useCounterContainer); +let counterRef = setupStore(useCounterContainer); -export { CounterContext, CounterWrapper, counterRef }; +export { counterRef }; diff --git a/examples/counter-react/src/store/counterWithReducer.store.js b/examples/counter-react/src/store/counterWithReducer.store.js index 32e5f06..9ebd6c4 100644 --- a/examples/counter-react/src/store/counterWithReducer.store.js +++ b/examples/counter-react/src/store/counterWithReducer.store.js @@ -23,6 +23,6 @@ const useCounterWithReducerStore = () => { }; }; -let [CounterWithReducerContext, CounterWithReducerWrapper, counterWithReducerRef] = setupStore(useCounterWithReducerStore); +let counterWithReducerRef = setupStore(useCounterWithReducerStore); -export { CounterWithReducerContext, CounterWithReducerWrapper, counterWithReducerRef}; +export { counterWithReducerRef }; diff --git a/osmosis/src/setupStore.js b/osmosis/src/setupStore.js index 2c09ed6..26893c0 100644 --- a/osmosis/src/setupStore.js +++ b/osmosis/src/setupStore.js @@ -15,6 +15,11 @@ const setupStore = useCustomHook => { const withStoreContext = WrappedComponent => props => { let store = useCustomHook(); + const e = "cannot have previous 'Provider' or 'Context' defined"; + if (store.Provider != undefined || store.Context != undefined) + { + return e; + } for (let key in store) { storeRef[key] = store[key]; } diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..fb57ccd --- /dev/null +++ b/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + From a0d275ebf94950db6899204274938ff4cce18968 Mon Sep 17 00:00:00 2001 From: Elyon Date: Thu, 12 Aug 2021 14:19:29 -0700 Subject: [PATCH 07/25] removing auto-generated yarn.lock file --- yarn.lock | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 yarn.lock diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index fb57ccd..0000000 --- a/yarn.lock +++ /dev/null @@ -1,4 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - From 504b936e268c6c43b59f40774381d77d28c5b5d0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Aug 2021 00:14:22 -0500 Subject: [PATCH 08/25] Bump path-parse from 1.0.6 to 1.0.7 in /examples/counter-react (#71) Bumps [path-parse](https://github.com/jbgutierrez/path-parse) from 1.0.6 to 1.0.7. - [Release notes](https://github.com/jbgutierrez/path-parse/releases) - [Commits](https://github.com/jbgutierrez/path-parse/commits/v1.0.7) --- updated-dependencies: - dependency-name: path-parse dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- examples/counter-react/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/counter-react/yarn.lock b/examples/counter-react/yarn.lock index d660380..9d5b06f 100644 --- a/examples/counter-react/yarn.lock +++ b/examples/counter-react/yarn.lock @@ -8047,9 +8047,9 @@ path-key@^3.0.0, path-key@^3.1.0: integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== path-parse@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c" - integrity sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== + version "1.0.7" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" + integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== path-to-regexp@0.1.7: version "0.1.7" From c04fe9160f5e8ca6ec98f5cda6fa4ca9b8ef2fc2 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Aug 2021 10:46:43 -0500 Subject: [PATCH 09/25] Bump url-parse from 1.5.1 to 1.5.3 in /examples/counter-react (#72) Bumps [url-parse](https://github.com/unshiftio/url-parse) from 1.5.1 to 1.5.3. - [Release notes](https://github.com/unshiftio/url-parse/releases) - [Commits](https://github.com/unshiftio/url-parse/compare/1.5.1...1.5.3) --- updated-dependencies: - dependency-name: url-parse dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- examples/counter-react/yarn.lock | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/counter-react/yarn.lock b/examples/counter-react/yarn.lock index 9d5b06f..9601556 100644 --- a/examples/counter-react/yarn.lock +++ b/examples/counter-react/yarn.lock @@ -10952,9 +10952,9 @@ url-loader@4.1.1: schema-utils "^3.0.0" url-parse@^1.4.3, url-parse@^1.4.7: - version "1.5.1" - resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.1.tgz#d5fa9890af8a5e1f274a2c98376510f6425f6e3b" - integrity sha512-HOfCOUJt7iSYzEx/UqgtwKRMC6EU91NFhsCHMv9oM03VJcVo2Qrp8T8kI9D7amFf1cu+/3CEhgb3rF9zL7k85Q== + version "1.5.3" + resolved "https://registry.yarnpkg.com/url-parse/-/url-parse-1.5.3.tgz#71c1303d38fb6639ade183c2992c8cc0686df862" + integrity sha512-IIORyIQD9rvj0A4CLWsHkBBJuNqWpFQe224b6j9t/ABmquIS0qDU2pY6kl6AuOrL5OkCXHMCFNe1jBcuAggjvQ== dependencies: querystringify "^2.1.1" requires-port "^1.0.0" From 7cdf62a45beecdb97e296620b0db3de5f41baae2 Mon Sep 17 00:00:00 2001 From: Elyon Date: Fri, 13 Aug 2021 13:12:05 -0700 Subject: [PATCH 10/25] throwing new error if provider or context already exists --- osmosis/src/setupStore.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osmosis/src/setupStore.js b/osmosis/src/setupStore.js index 26893c0..1072ff1 100644 --- a/osmosis/src/setupStore.js +++ b/osmosis/src/setupStore.js @@ -15,10 +15,9 @@ const setupStore = useCustomHook => { const withStoreContext = WrappedComponent => props => { let store = useCustomHook(); - const e = "cannot have previous 'Provider' or 'Context' defined"; if (store.Provider != undefined || store.Context != undefined) { - return e; + throw "cannot have previous 'Provider' or 'Context' defined"; } for (let key in store) { storeRef[key] = store[key]; From 01b42bb888d15e560711de0a5fe14f04dfc495e7 Mon Sep 17 00:00:00 2001 From: Elyon Date: Fri, 13 Aug 2021 14:08:29 -0700 Subject: [PATCH 11/25] updating to export as default --- examples/counter-react/src/__tests__/counter.spec.js | 1 + .../counter-react/src/store/__tests__/counter.store.spec.js | 2 +- examples/counter-react/src/store/counter.store.js | 2 +- examples/counter-react/src/store/index.js | 2 +- osmosis/src/index.js | 2 +- osmosis/src/setupStore.js | 2 +- 6 files changed, 6 insertions(+), 5 deletions(-) diff --git a/examples/counter-react/src/__tests__/counter.spec.js b/examples/counter-react/src/__tests__/counter.spec.js index 1ac11be..ac519f2 100644 --- a/examples/counter-react/src/__tests__/counter.spec.js +++ b/examples/counter-react/src/__tests__/counter.spec.js @@ -11,6 +11,7 @@ describe('Counter', () => { incrementCount: jest.fn(), decrementCount: jest.fn() }; + console.log(counterRef); let ContextComponent = () => ( diff --git a/examples/counter-react/src/store/__tests__/counter.store.spec.js b/examples/counter-react/src/store/__tests__/counter.store.spec.js index 0925230..39bf5bb 100644 --- a/examples/counter-react/src/store/__tests__/counter.store.spec.js +++ b/examples/counter-react/src/store/__tests__/counter.store.spec.js @@ -1,5 +1,5 @@ import React, { useContext } from 'react'; -import { counterRef } from '../counter.store'; +import counterRef from '../counter.store'; import { render } from '@testing-library/react'; import { act } from 'react-dom/test-utils'; diff --git a/examples/counter-react/src/store/counter.store.js b/examples/counter-react/src/store/counter.store.js index 396b605..9062324 100644 --- a/examples/counter-react/src/store/counter.store.js +++ b/examples/counter-react/src/store/counter.store.js @@ -27,4 +27,4 @@ const useCounterContainer = () => { let counterRef = setupStore(useCounterContainer); -export { counterRef }; +export default counterRef ; diff --git a/examples/counter-react/src/store/index.js b/examples/counter-react/src/store/index.js index 55c2a03..fc45030 100644 --- a/examples/counter-react/src/store/index.js +++ b/examples/counter-react/src/store/index.js @@ -1,2 +1,2 @@ -export { CounterContext, CounterWrapper, counterRef } from './counter.store'; +export { default as counterRef } from './counter.store'; export { CounterWithReducerContext, CounterWithReducerWrapper, counterWithReducerRef} from './counterWithReducer.store.js'; diff --git a/osmosis/src/index.js b/osmosis/src/index.js index 233b0a5..bec99df 100644 --- a/osmosis/src/index.js +++ b/osmosis/src/index.js @@ -1,5 +1,5 @@ import { StoreProvider } from './storeProvider.js'; -import { setupStore } from './setupStore.js'; +import setupStore from './setupStore.js'; import { usePersistedState, configureUsePersistedState } from './usePersistedState.js'; export { setupStore, StoreProvider, usePersistedState, configureUsePersistedState }; diff --git a/osmosis/src/setupStore.js b/osmosis/src/setupStore.js index 1072ff1..6096a45 100644 --- a/osmosis/src/setupStore.js +++ b/osmosis/src/setupStore.js @@ -34,4 +34,4 @@ const setupStore = useCustomHook => { return storeRef; }; -export { setupStore }; +export default setupStore; From c0fd236530389f0c44c011bae11e4377266eea7b Mon Sep 17 00:00:00 2001 From: Elyon Date: Fri, 13 Aug 2021 14:14:33 -0700 Subject: [PATCH 12/25] updating name to reflect no longer being a reference --- .../counter-react/src/__tests__/counter.spec.js | 13 ++++++------- examples/counter-react/src/counter.js | 4 ++-- .../src/store/__tests__/counter.store.spec.js | 6 +++--- examples/counter-react/src/store/counter.store.js | 4 ++-- examples/counter-react/src/store/index.js | 2 +- 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/examples/counter-react/src/__tests__/counter.spec.js b/examples/counter-react/src/__tests__/counter.spec.js index ac519f2..f921b7e 100644 --- a/examples/counter-react/src/__tests__/counter.spec.js +++ b/examples/counter-react/src/__tests__/counter.spec.js @@ -1,21 +1,20 @@ import React from 'react'; import Counter from '../counter'; -import { counterRef } from '../store'; +import { CounterStore } from '../store'; import { render, fireEvent } from '@testing-library/react'; describe('Counter', () => { - const CounterStore = { + const counterStore = { state: { count: 0 }, incrementCount: jest.fn(), decrementCount: jest.fn() }; - console.log(counterRef); let ContextComponent = () => ( - + - + ); it('renders default', async () => { let wrapper = await render(); @@ -24,11 +23,11 @@ describe('Counter', () => { it('tests increment button', async () => { let wrapper = await render(); fireEvent.click(wrapper.getByTestId('increment')); - expect(CounterStore.incrementCount).toHaveBeenCalled(); + expect(counterStore.incrementCount).toHaveBeenCalled(); }); it('tests decrement button', async () => { let wrapper = await render(); fireEvent.click(wrapper.getByTestId('decrement')); - expect(CounterStore.decrementCount).toHaveBeenCalled(); + expect(counterStore.decrementCount).toHaveBeenCalled(); }); }); diff --git a/examples/counter-react/src/counter.js b/examples/counter-react/src/counter.js index 27d7892..4863867 100644 --- a/examples/counter-react/src/counter.js +++ b/examples/counter-react/src/counter.js @@ -1,8 +1,8 @@ import React, { useContext } from 'react'; -import { counterRef } from './store'; +import { CounterStore } from './store'; const Counter = () => { - const [counterContext] = useContext(counterRef.Context); + const [counterContext] = useContext(CounterStore.Context); let { count } = counterContext.state; return ( diff --git a/examples/counter-react/src/store/__tests__/counter.store.spec.js b/examples/counter-react/src/store/__tests__/counter.store.spec.js index 39bf5bb..a9c0ab0 100644 --- a/examples/counter-react/src/store/__tests__/counter.store.spec.js +++ b/examples/counter-react/src/store/__tests__/counter.store.spec.js @@ -1,13 +1,13 @@ import React, { useContext } from 'react'; -import counterRef from '../counter.store'; +import CounterStore from '../counter.store'; import { render } from '@testing-library/react'; import { act } from 'react-dom/test-utils'; describe('CounterStore', () => { let store; const renderStore = () => { - let Prep = counterRef.Provider(() => { - store = useContext(counterRef.Context)[0]; + let Prep = CounterStore.Provider(() => { + store = useContext(CounterStore.Context)[0]; return null; }); render(); diff --git a/examples/counter-react/src/store/counter.store.js b/examples/counter-react/src/store/counter.store.js index 9062324..d4dbbbe 100644 --- a/examples/counter-react/src/store/counter.store.js +++ b/examples/counter-react/src/store/counter.store.js @@ -25,6 +25,6 @@ const useCounterContainer = () => { }; }; -let counterRef = setupStore(useCounterContainer); +let CounterStore = setupStore(useCounterContainer); -export default counterRef ; +export default CounterStore ; diff --git a/examples/counter-react/src/store/index.js b/examples/counter-react/src/store/index.js index fc45030..d76afb8 100644 --- a/examples/counter-react/src/store/index.js +++ b/examples/counter-react/src/store/index.js @@ -1,2 +1,2 @@ -export { default as counterRef } from './counter.store'; +export { default as CounterStore } from './counter.store'; export { CounterWithReducerContext, CounterWithReducerWrapper, counterWithReducerRef} from './counterWithReducer.store.js'; From f4cfe52c39925ba9ddb92c4fbcda97dfd510570c Mon Sep 17 00:00:00 2001 From: Elyon Date: Fri, 13 Aug 2021 14:16:17 -0700 Subject: [PATCH 13/25] splitting up the checks --- osmosis/src/setupStore.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/osmosis/src/setupStore.js b/osmosis/src/setupStore.js index 6096a45..97bf659 100644 --- a/osmosis/src/setupStore.js +++ b/osmosis/src/setupStore.js @@ -15,10 +15,9 @@ const setupStore = useCustomHook => { const withStoreContext = WrappedComponent => props => { let store = useCustomHook(); - if (store.Provider != undefined || store.Context != undefined) - { - throw "cannot have previous 'Provider' or 'Context' defined"; - } + if (!!store.Context) throw new Error("'Context' property is protected and cannot exist on a store object"); + if (!!store.Provider) throw new Error("'Provider' property is protected and cannot exist on a store object"); + for (let key in store) { storeRef[key] = store[key]; } From cae0181516c9fa7a0900de351efc242e45640804 Mon Sep 17 00:00:00 2001 From: Elyon Date: Fri, 13 Aug 2021 14:53:21 -0700 Subject: [PATCH 14/25] staying consistent with osmosis exports --- osmosis/src/index.js | 2 +- osmosis/src/setupStore.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/osmosis/src/index.js b/osmosis/src/index.js index bec99df..233b0a5 100644 --- a/osmosis/src/index.js +++ b/osmosis/src/index.js @@ -1,5 +1,5 @@ import { StoreProvider } from './storeProvider.js'; -import setupStore from './setupStore.js'; +import { setupStore } from './setupStore.js'; import { usePersistedState, configureUsePersistedState } from './usePersistedState.js'; export { setupStore, StoreProvider, usePersistedState, configureUsePersistedState }; diff --git a/osmosis/src/setupStore.js b/osmosis/src/setupStore.js index 97bf659..067649c 100644 --- a/osmosis/src/setupStore.js +++ b/osmosis/src/setupStore.js @@ -33,4 +33,4 @@ const setupStore = useCustomHook => { return storeRef; }; -export default setupStore; +export { setupStore }; From c11c53b385396242daaf8abdd5a2de5f6b06e055 Mon Sep 17 00:00:00 2001 From: Elyon Date: Fri, 13 Aug 2021 15:05:45 -0700 Subject: [PATCH 15/25] updating counterWithReducer to default export --- examples/counter-react/src/dispatchCounter.js | 4 ++-- examples/counter-react/src/store/counterWithReducer.store.js | 4 ++-- examples/counter-react/src/store/index.js | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/counter-react/src/dispatchCounter.js b/examples/counter-react/src/dispatchCounter.js index 53940a3..c02dca3 100644 --- a/examples/counter-react/src/dispatchCounter.js +++ b/examples/counter-react/src/dispatchCounter.js @@ -1,8 +1,8 @@ import React, { useContext } from 'react'; -import { counterWithReducerRef } from './store'; +import { CounterWithReducerRef } from './store'; const PersistedCounter = () => { - const [counterContext] = useContext(counterWithReducerRef.Context); + const [counterContext] = useContext(CounterWithReducerRef.Context); let { dispatch, counterState: { count }} = counterContext; return ( diff --git a/examples/counter-react/src/store/counterWithReducer.store.js b/examples/counter-react/src/store/counterWithReducer.store.js index 9ebd6c4..a8c572c 100644 --- a/examples/counter-react/src/store/counterWithReducer.store.js +++ b/examples/counter-react/src/store/counterWithReducer.store.js @@ -23,6 +23,6 @@ const useCounterWithReducerStore = () => { }; }; -let counterWithReducerRef = setupStore(useCounterWithReducerStore); +let CounterWithReducerRef = setupStore(useCounterWithReducerStore); -export { counterWithReducerRef }; +export default CounterWithReducerRef; diff --git a/examples/counter-react/src/store/index.js b/examples/counter-react/src/store/index.js index d76afb8..1859345 100644 --- a/examples/counter-react/src/store/index.js +++ b/examples/counter-react/src/store/index.js @@ -1,2 +1,2 @@ export { default as CounterStore } from './counter.store'; -export { CounterWithReducerContext, CounterWithReducerWrapper, counterWithReducerRef} from './counterWithReducer.store.js'; +export { default as CounterWithReducerRef } from './counterWithReducer.store.js'; From 2acd1cb70701debb781802b6c86fd1303a94ba68 Mon Sep 17 00:00:00 2001 From: Elyon Date: Fri, 13 Aug 2021 15:21:17 -0700 Subject: [PATCH 16/25] updating example project --- examples/counter-react/src/App.js | 4 ++-- examples/counter-react/src/persistedCounter.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/counter-react/src/App.js b/examples/counter-react/src/App.js index 996a4cf..0b36708 100644 --- a/examples/counter-react/src/App.js +++ b/examples/counter-react/src/App.js @@ -1,5 +1,5 @@ import { StoreProvider, configureUsePersistedState } from '@shipt/osmosis'; -import { counterRef, CounterWithReducerWrapper } from './store'; +import { CounterStore, CounterWithReducerRef } from './store'; import Counter from './counter'; import PersistedCounter from './persistedCounter.js'; @@ -20,4 +20,4 @@ const App = () => { ); }; -export default StoreProvider([counterRef.Provider, CounterWithReducerWrapper], App); +export default StoreProvider([CounterStore.Provider, CounterWithReducerRef.Provider], App); diff --git a/examples/counter-react/src/persistedCounter.js b/examples/counter-react/src/persistedCounter.js index 57f6fc4..5d858af 100644 --- a/examples/counter-react/src/persistedCounter.js +++ b/examples/counter-react/src/persistedCounter.js @@ -1,8 +1,8 @@ import React, { useContext } from 'react'; -import { CounterContext } from './store'; +import { CounterStore } from './store'; const PersistedCounter = () => { - const [counterContext] = useContext(CounterContext); + const [counterContext] = useContext(CounterStore.Context); let { persistedCount } = counterContext.state; return ( From 2aee0b2d0e4b239f76e6e3a4ff0ed371fa719448 Mon Sep 17 00:00:00 2001 From: Elyon Date: Fri, 13 Aug 2021 15:40:44 -0700 Subject: [PATCH 17/25] updating counterWithReducerRef to CounterWithreducerStore for naming consistency --- examples/counter-react/src/App.js | 4 ++-- examples/counter-react/src/dispatchCounter.js | 4 ++-- examples/counter-react/src/store/counterWithReducer.store.js | 4 ++-- examples/counter-react/src/store/index.js | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/counter-react/src/App.js b/examples/counter-react/src/App.js index 0b36708..f01dee1 100644 --- a/examples/counter-react/src/App.js +++ b/examples/counter-react/src/App.js @@ -1,5 +1,5 @@ import { StoreProvider, configureUsePersistedState } from '@shipt/osmosis'; -import { CounterStore, CounterWithReducerRef } from './store'; +import { CounterStore, CounterWithReducerStore } from './store'; import Counter from './counter'; import PersistedCounter from './persistedCounter.js'; @@ -20,4 +20,4 @@ const App = () => { ); }; -export default StoreProvider([CounterStore.Provider, CounterWithReducerRef.Provider], App); +export default StoreProvider([CounterStore.Provider, CounterWithReducerStore.Provider], App); diff --git a/examples/counter-react/src/dispatchCounter.js b/examples/counter-react/src/dispatchCounter.js index c02dca3..d31271d 100644 --- a/examples/counter-react/src/dispatchCounter.js +++ b/examples/counter-react/src/dispatchCounter.js @@ -1,8 +1,8 @@ import React, { useContext } from 'react'; -import { CounterWithReducerRef } from './store'; +import { CounterWithReducerStore } from './store'; const PersistedCounter = () => { - const [counterContext] = useContext(CounterWithReducerRef.Context); + const [counterContext] = useContext(CounterWithReducerStore.Context); let { dispatch, counterState: { count }} = counterContext; return ( diff --git a/examples/counter-react/src/store/counterWithReducer.store.js b/examples/counter-react/src/store/counterWithReducer.store.js index a8c572c..1e305f2 100644 --- a/examples/counter-react/src/store/counterWithReducer.store.js +++ b/examples/counter-react/src/store/counterWithReducer.store.js @@ -23,6 +23,6 @@ const useCounterWithReducerStore = () => { }; }; -let CounterWithReducerRef = setupStore(useCounterWithReducerStore); +let CounterWithReducerStore = setupStore(useCounterWithReducerStore); -export default CounterWithReducerRef; +export default CounterWithReducerStore; diff --git a/examples/counter-react/src/store/index.js b/examples/counter-react/src/store/index.js index 1859345..d1a6e1e 100644 --- a/examples/counter-react/src/store/index.js +++ b/examples/counter-react/src/store/index.js @@ -1,2 +1,2 @@ export { default as CounterStore } from './counter.store'; -export { default as CounterWithReducerRef } from './counterWithReducer.store.js'; +export { default as CounterWithReducerStore } from './counterWithReducer.store.js'; From c81dbbbbeaa797305a4d451949cc1c4dea2f08f3 Mon Sep 17 00:00:00 2001 From: chaceburnette Date: Mon, 16 Aug 2021 12:58:14 -0500 Subject: [PATCH 18/25] allow proxy opt in (#73) * allow proxy opt in * add back the context and provider references that were accidentally removed in the conflict resolution --- osmosis/src/setupStore.js | 53 +++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 7 deletions(-) diff --git a/osmosis/src/setupStore.js b/osmosis/src/setupStore.js index 067649c..88465a7 100644 --- a/osmosis/src/setupStore.js +++ b/osmosis/src/setupStore.js @@ -1,25 +1,50 @@ import React, { createContext } from 'react'; +const _defaultConfig = { proxyEnabled: false }; + /** * @callback useCustomHook * @returns {Object} */ +/** + * @typedef SetupStoreConfig + * @type {Object} + * @property {boolean} proxyEnabled - Determines if the store setup should use proxies internally for the store ref, only if proxies are supported + */ + +/** + * @typedef Store + * @type {Object} + * @property {Object} Context - The React Context for the store + * @property {Object} Provider - The higher order component provider for the store + */ + /** * @param {useCustomHook} useCustomHook - * @returns {Object[]} + * @param {SetupStoreConfig} [config = { proxyEnabled: false }] - The setup store config + * @returns {Store} */ -const setupStore = useCustomHook => { +const setupStore = (useCustomHook, config = _defaultConfig) => { const StoreContext = createContext(); + // If proxy is not supported let storeRef = { state: {} }; + // If proxy is supported + let storeProxy; + let storeProxyObject = { ref: { state: {} } }; + const withStoreContext = WrappedComponent => props => { let store = useCustomHook(); if (!!store.Context) throw new Error("'Context' property is protected and cannot exist on a store object"); if (!!store.Provider) throw new Error("'Provider' property is protected and cannot exist on a store object"); - for (let key in store) { - storeRef[key] = store[key]; + if (storeProxy) { + storeProxyObject.ref = store; + } else { + for (let key in store) { + storeRef[key] = store[key]; + } } return ( @@ -28,9 +53,23 @@ const setupStore = useCustomHook => { ); }; - storeRef.Context = StoreContext; - storeRef.Provider = withStoreContext; - return storeRef; + + if (!!Proxy && config.proxyEnabled) { + storeProxy = new Proxy(storeProxyObject, { + get: (target, property) => { + if (property === 'Context') return StoreContext; + if (property === 'Provider') return withStoreContext; + return target.ref[property]; + }, + set: (target, property, value) => (target.ref[property] = value) + }); + } else { + storeRef.Context = StoreContext; + storeRef.Provider = withStoreContext; + } + + + return storeProxy || storeRef; }; export { setupStore }; From 7b4362058e639dfe42df52df845a06ae8b8524ff Mon Sep 17 00:00:00 2001 From: chaceburnette Date: Mon, 16 Aug 2021 23:29:43 -0500 Subject: [PATCH 19/25] modify usePersistedState to support functional state updates (#74) --- .../counter-react/src/store/counter.store.js | 4 +++- osmosis/src/usePersistedState.js | 22 ++++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/examples/counter-react/src/store/counter.store.js b/examples/counter-react/src/store/counter.store.js index d4dbbbe..bcc0c09 100644 --- a/examples/counter-react/src/store/counter.store.js +++ b/examples/counter-react/src/store/counter.store.js @@ -9,8 +9,10 @@ const useCounterContainer = () => { const decrementCount = () => setCount(count - 1); - const incrementPersistedCount = () => setPersistedCount(persistedCount + 1); + // showing supporting functional state updates + const incrementPersistedCount = () => setPersistedCount(currentCount => currentCount + 1); + // showing supporting non-functional state updates const decrementPersistedCount = () => setPersistedCount(persistedCount - 1); return { diff --git a/osmosis/src/usePersistedState.js b/osmosis/src/usePersistedState.js index f97e206..210e55a 100644 --- a/osmosis/src/usePersistedState.js +++ b/osmosis/src/usePersistedState.js @@ -34,17 +34,27 @@ export const usePersistedState = (initValue, key) => { }; const setPersistedState = value => { - if (setItem) setItem(key, value); - setState({ - value, - isLoaded: true - }); + if (typeof value === 'function') { + setState(currentValue => { + const newValue = value(currentValue.value); + if (setItem) setItem(key, newValue); + return { + value: newValue, + isLoaded: true + }; + }); + } else { + if (setItem) setItem(key, value); + setState({ + value, + isLoaded: true + }); + } }; return [state.value, setPersistedState, state.isLoaded]; }; - /** * @callback getItem * @param {string} key From acdb5b9f7df670c1d62b91dda94b92dd9c8c6b04 Mon Sep 17 00:00:00 2001 From: chaceburnette Date: Tue, 17 Aug 2021 14:36:13 -0500 Subject: [PATCH 20/25] Update version to 1.2.0 --- osmosis/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osmosis/package.json b/osmosis/package.json index 59c9cd6..eee617e 100644 --- a/osmosis/package.json +++ b/osmosis/package.json @@ -1,6 +1,6 @@ { "name": "@shipt/osmosis", - "version": "1.1.1", + "version": "1.2.0", "description": "A lightweight state management library for React and React Native", "keywords": [ "react", From 2772eadc37a717882704f6f1569c1ac19a94eef5 Mon Sep 17 00:00:00 2001 From: chaceburnette Date: Tue, 17 Aug 2021 14:43:08 -0500 Subject: [PATCH 21/25] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d63afa7..83448c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## v1.2.0 + +* BREAKING CHANGE - Modified the return format for `setupStore` to be a single object instead of an array of parts +* usePersistedState - the set state function now supports the functional state update syntax + ## v1.1.1 * Minor dependency updates From dd8a2006cf410b1ff5ce2836f23d07c065b03b5d Mon Sep 17 00:00:00 2001 From: Elyon Olaniran Date: Wed, 18 Aug 2021 12:08:35 -0700 Subject: [PATCH 22/25] elyonolaniran/ch364666/update-osmosis-docs (#76) * updating osmosis docs to reflect code changes * reordering store descriptions * reinstating the array parameter in export * calling the object instead of context --- osmosis/README.md | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/osmosis/README.md b/osmosis/README.md index 185f5f4..08688c5 100644 --- a/osmosis/README.md +++ b/osmosis/README.md @@ -24,15 +24,15 @@ import { setupStore } from '@shipt/osmosis'; The `setupStore` function takes in an argument that is just a custom hook. The custom hook will return a single object that represents a slice of state and any functions needed to operate on that state. -`setupStore` returns three variables +`setupStore` returns one variable with 2 properties: `Context` and `Provider` ```js -let [storeContext, wrapperFunction, storeRef] = setupStore(useStateStore); +let store = setupStore(useStateStore); ``` -- `storeContext` is a React context variable that gives you access to the state and functions of your store -- `wrapperFunction` is simply a higher-order component used to provide the store to the app and should be used to wrap the top-level component in the app -- `storeRef` is an object that gives you access to state variables and functions without causing re-renders when changes occur +- store : a ref to the store object returned from the supplied custom hook +- store.Context - a React context variable that gives you access to the state and functions of your store +- store.Provider - a higher-order component used to provide the store to the app To connect the state throughout your app you have to import the `StoreProvider` function which is simply a utility for combining several `wrapperFunction`'s into a single higher order component. @@ -75,27 +75,25 @@ const useCounterStore = () => { }; }; -let [CounterContext, wrapCounter, counterRef] = setupStore(useCounterStore); +let CounterStore = setupStore(useCounterStore); -export { CounterContext, wrapCounter }; - -export default counterRef; +export default CounterStore; ``` ```jsx //counter.js import React, { useContext } from 'react'; -import { CounterContext } from './counter.store'; +import { CounterStore } from './counter.store'; export default () => { - const [counterContext] = useContext(CounterContext); - let { count } = counterContext.state; + const [counterStore] = useContext(CounterStore.Context); + let { count } = counterStore.state; return (

{count}

- - + +
); }; @@ -104,10 +102,10 @@ export default () => { ```jsx //index.js Root Component import { StoreProvider } from '@shipt/osmosis'; -import { wrapCounter } from './counter.store'; +import { CounterStore } from './counter.store'; import Counter from './counter'; -export default StoreProvider([wrapCounter], Counter); +export default StoreProvider([CounterStore.Provider], Counter); ``` ## State Persistence with usePersistedState From b2a895359f0282b985222b5469350b7c2506324b Mon Sep 17 00:00:00 2001 From: chaceburnette Date: Wed, 18 Aug 2021 14:17:28 -0500 Subject: [PATCH 23/25] Update README.md --- osmosis/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osmosis/README.md b/osmosis/README.md index 08688c5..5c8099a 100644 --- a/osmosis/README.md +++ b/osmosis/README.md @@ -30,7 +30,7 @@ The `setupStore` function takes in an argument that is just a custom hook. The c let store = setupStore(useStateStore); ``` -- store : a ref to the store object returned from the supplied custom hook +- store - a ref to the store object returned from the supplied custom hook - store.Context - a React context variable that gives you access to the state and functions of your store - store.Provider - a higher-order component used to provide the store to the app From 20a3b59713d277d7d1ec1adc6bc47bf984d71d64 Mon Sep 17 00:00:00 2001 From: chaceburnette Date: Wed, 18 Aug 2021 14:18:48 -0500 Subject: [PATCH 24/25] Update README.md --- osmosis/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osmosis/README.md b/osmosis/README.md index 5c8099a..a8633fa 100644 --- a/osmosis/README.md +++ b/osmosis/README.md @@ -30,9 +30,9 @@ The `setupStore` function takes in an argument that is just a custom hook. The c let store = setupStore(useStateStore); ``` -- store - a ref to the store object returned from the supplied custom hook -- store.Context - a React context variable that gives you access to the state and functions of your store -- store.Provider - a higher-order component used to provide the store to the app +- `store` - a ref to the store object returned from the supplied custom hook +- `store.Context` - a React context variable that gives you access to the state and functions of your store +- `store.Provider` - a higher-order component used to provide the store to the app To connect the state throughout your app you have to import the `StoreProvider` function which is simply a utility for combining several `wrapperFunction`'s into a single higher order component. From 3a0a1976a5aac0b88eeaf320cd4d74d3f136a677 Mon Sep 17 00:00:00 2001 From: chaceburnette Date: Wed, 18 Aug 2021 14:20:45 -0500 Subject: [PATCH 25/25] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83448c1..2292bc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## v1.2.0 * BREAKING CHANGE - Modified the return format for `setupStore` to be a single object instead of an array of parts -* usePersistedState - the set state function now supports the functional state update syntax +* `usePersistedState` - the set state function now supports the functional state update syntax ## v1.1.1 @@ -20,7 +20,7 @@ ## v1.0.1 * Cleaning up some unused files -* Adding better error messages for usePersistedState and StoreProvider +* Adding better error messages for `usePersistedState` and `StoreProvider` * README updates and tweaks ## v1.0.0