-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from shipt/development
Release 1.1.0
- Loading branch information
Showing
5 changed files
with
19 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
import { StoreProvider } from './storeProvider.js'; | ||
import { Container, setupStore } from './setupStore.js'; | ||
import { setupStore } from './setupStore.js'; | ||
import { usePersistedState, configureUsePersistedState } from './usePersistedState.js'; | ||
|
||
export { Container, setupStore, StoreProvider, usePersistedState, configureUsePersistedState }; | ||
export { setupStore, StoreProvider, usePersistedState, configureUsePersistedState }; | ||
export default { | ||
Container, | ||
setupStore, | ||
StoreProvider, | ||
usePersistedState, | ||
configureUsePersistedState | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,32 @@ | ||
import React, { createContext } from 'react'; | ||
|
||
class Container { | ||
constructor() { | ||
this.container = { | ||
state: {} | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* @callback useCustomHook | ||
* @returns {Object} | ||
*/ | ||
|
||
/** | ||
* @param {useCustomHook} useCustomHook | ||
* @param {Object=} classContainer - Deprecated: classContainer support will be removed in a future release | ||
* @returns {Object[]} | ||
*/ | ||
const setupStore = (useCustomHook, classContainer) => { | ||
const setupStore = useCustomHook => { | ||
const StoreContext = createContext(); | ||
let store = { state: {} }; | ||
let storeRef = { state: {} }; | ||
|
||
const withStoreContext = WrappedComponent => props => { | ||
let container = useCustomHook(); | ||
if (classContainer) { | ||
classContainer.container = container; | ||
} else { | ||
for (let key in container) { | ||
store[key] = container[key]; | ||
} | ||
let store = useCustomHook(); | ||
for (let key in store) { | ||
storeRef[key] = store[key]; | ||
} | ||
|
||
return ( | ||
<StoreContext.Provider value={[container]}> | ||
<StoreContext.Provider value={[store]}> | ||
<WrappedComponent {...props} /> | ||
</StoreContext.Provider> | ||
); | ||
}; | ||
|
||
return [StoreContext, withStoreContext, store]; | ||
return [StoreContext, withStoreContext, storeRef]; | ||
}; | ||
|
||
export { Container, setupStore }; | ||
export { setupStore }; |