Skip to content

Commit 7973d3c

Browse files
committed
fix(overmind): deep clone state to avoid bugs when part of it is reused
1 parent 6d1172b commit 7973d3c

File tree

1 file changed

+13
-3
lines changed
  • packages/node_modules/overmind/src

1 file changed

+13
-3
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const dynamicModule = ((cb) => (namespace) =>
3434
*/
3535

3636
export type Configuration = {
37-
onInitialize?: any
37+
onInitialize?: Action<undefined>
3838
state?: any
3939
effects?: any
4040
actions?: any
@@ -149,6 +149,7 @@ export default class App<
149149
EvalConfig extends TConfig<Config>
150150
> {
151151
private proxyStateTree: ProxyStateTree
152+
initialized: Promise<{}>
152153
eventHub: EventEmitter<Events>
153154
devtools: Devtools
154155
actions: {
@@ -256,7 +257,9 @@ export default class App<
256257
const onInitialize = operators.compose(configuration.onInitialize)
257258
// @ts-ignore
258259
onInitialize.displayName = 'onInitialize'
259-
onInitialize(undefined)
260+
this.initialized = Promise.resolve(onInitialize(undefined))
261+
} else {
262+
this.initialized = Promise.resolve({})
260263
}
261264
}
262265
private initializeDevtools(host, actionChain, eventHub, proxyStateTree) {
@@ -375,7 +378,12 @@ export default class App<
375378
}
376379
private transformStateToPlainObject(state: {}) {
377380
return Object.keys(state).reduce((aggr, key) => {
378-
aggr[key] = state[key]
381+
const value = state[key]
382+
if (typeof value === 'object') {
383+
aggr[key] = this.transformStateToPlainObject(value)
384+
} else {
385+
aggr[key] = value
386+
}
379387

380388
return aggr
381389
}, {})
@@ -385,8 +393,10 @@ export default class App<
385393
if (configuration.actions) {
386394
actions = configuration.actions
387395
}
396+
console.log('getActions[0]', configuration)
388397

389398
const evaluatedActions = Object.keys(actions).reduce((aggr, name) => {
399+
console.log('getActions', name, typeof actions[name])
390400
if (typeof actions[name] === 'function') {
391401
return Object.assign(aggr, {
392402
[name]: actions[name](operators),

0 commit comments

Comments
 (0)