Skip to content

Commit

Permalink
fix(defaults): fixed wrong defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
BowlingX committed Dec 5, 2019
1 parent 0c2290e commit 5841ecb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions src/lib/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export const historyManagement = (historyInstance: History) => apply => (
state: { __g__: true }
})

// We safe the current state of `query` for all affected namespaces
return {
...values,
namespaces: {
Expand Down Expand Up @@ -154,6 +155,10 @@ export const historyManagement = (historyInstance: History) => apply => (
api
)

/**
* If a namespace is given, will forward the mutation instead of updating
* the whole state. Initializes the namespace if it does not exist yet
*/
const namespaceProducer = (fn, ns?: string) => state => {
if (!ns) {
const result = fn(state.namespaces)
Expand Down Expand Up @@ -198,9 +203,6 @@ export const converter = (historyInstance: History) => (set, get) => {
}
const nextQueries = parse(location.search)
const namespaces = get().namespaces
// We skip one frame here in case we do route changes
// Because we rely on the state listener in store, it does not fire if it's not initialized
// TODO: Maybe find a better solution, but everything I tried yielded to double rendering of the component
Object.keys(namespaces).forEach(ns => {
set(
state => {
Expand Down Expand Up @@ -245,6 +247,7 @@ export const converter = (historyInstance: History) => (set, get) => {
HistoryEventType.REPLACE
)
},
/** the initial queries when the script got executed first (usually on page load). */
initialQueries,
/** here we store all data and configurations for the different namespaces */
namespaces: {},
Expand Down Expand Up @@ -304,12 +307,12 @@ export const converter = (historyInstance: History) => (set, get) => {
set(state => fn(state.values), HistoryEventType.REPLACE, ns),
resetPush: (ns: string) => reset(ns, HistoryEventType.PUSH),
resetReplace: (ns: string) => reset(ns, HistoryEventType.REPLACE),
/** cleans up this instance */
unregister: () => {
set(() => {
// return a new object for namespaces
return {}
}, HistoryEventType.REGISTER)

// unregister history event listener
unregisterListener()
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export const factoryParameters = <T = object>(
}, [api])

const [currentState, setCurrentState] = useState({
initialValues: defaultInitialValues,
initialValues: initialRegisterState.initialValues,
values: initialRegisterState.values
})

Expand Down

0 comments on commit 5841ecb

Please sign in to comment.