Skip to content

Commit 4f410c3

Browse files
committed
fix(overmind): deep clone state on app creation
this avoids bugs when some parts of a configuration state are reused
1 parent fe3ffc2 commit 4f410c3

File tree

1 file changed

+16
-9
lines changed
  • packages/node_modules/overmind/src

1 file changed

+16
-9
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
import { ActionChain } from 'action-chain'
22
import { EventEmitter } from 'betsy'
33
import ProxyStateTree from 'proxy-state-tree'
4-
import Derived from './derived'
5-
import Devtools, { Message, safeValue } from './Devtools'
4+
65
import ActionClass, {
7-
IValueAction,
8-
INoValueAction,
96
Compose,
7+
INoValueAction,
8+
IValueAction,
109
createOperators,
1110
} from './Action'
12-
import Reaction from './reaction'
11+
import Derived from './derived'
12+
import Devtools, { Message, safeValue } from './Devtools'
1313
import {
1414
DynamicModule,
15-
SubType,
16-
Events,
1715
EventType,
16+
Events,
1817
Options,
18+
SubType,
1919
} from './internalTypes'
20+
import Reaction from './reaction'
2021

2122
export { IValueAction, Compose, EventType }
2223

@@ -529,8 +530,14 @@ export default class App<
529530
}
530531
private processState(state: {}) {
531532
return Object.keys(state).reduce((aggr, key) => {
532-
aggr[key] =
533-
typeof state[key] === 'function' ? new Derived(state[key]) : state[key]
533+
const value = state[key]
534+
if (typeof value === 'object') {
535+
aggr[key] = this.processState(value)
536+
} else if (typeof value === 'function') {
537+
aggr[key] = new Derived(value)
538+
} else {
539+
aggr[key] = value
540+
}
534541

535542
return aggr
536543
}, {})

0 commit comments

Comments
 (0)