Skip to content

Commit 97314a8

Browse files
fix(overmind): fix not having state on root when merging config
1 parent 8f7ecf6 commit 97314a8

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

packages/node_modules/overmind/src/config/config.test.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,18 @@ describe('Config', () => {
9595
expect(merged.state.configB.bar).toEqual('baz')
9696
})
9797

98+
test('should merge without root state', () => {
99+
const configA = {}
100+
const configB = {
101+
state: {
102+
bar: 'baz',
103+
},
104+
}
105+
const merged = merge(configA, namespaced({ configB }))
106+
107+
expect(merged.state.configB.bar).toEqual('baz')
108+
})
109+
98110
test('should keep context when lazy loading namespaces', async () => {
99111
const config = {
100112
state: {
@@ -103,20 +115,21 @@ describe('Config', () => {
103115
actions: {
104116
changeFoo(context) {
105117
context.state.config.foo = 'bar2'
106-
}
107-
}
118+
},
119+
},
108120
}
109-
110-
const overmind = createOvermindMock(lazy({
111-
config: () => Promise.resolve(config)
112-
}))
121+
122+
const overmind = createOvermindMock(
123+
lazy({
124+
config: () => Promise.resolve(config),
125+
})
126+
)
113127

114128
await overmind.onInitialize()
115129

116130
await overmind.actions.lazy.loadConfig('config')
117131
// @ts-ignore
118132
overmind.actions.config.changeFoo()
119133
expect(overmind.state.config!.foo).toEqual('bar2')
120-
121134
})
122135
})

packages/node_modules/overmind/src/config/merge.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ export function merge<
123123
configI: I
124124
): A & B & C & D & E & F & G & H & I
125125

126-
127-
128126
export function merge(...configurations: IConfiguration[]): IConfiguration {
129127
const initializers = configurations.reduce(
130128
(aggr, config) =>
@@ -178,6 +176,9 @@ export function merge(...configurations: IConfiguration[]): IConfiguration {
178176
}
179177
},
180178
{
179+
state: {},
180+
actions: {},
181+
effects: {},
181182
...rootConfiguration,
182183
onInitialize: initializers.length
183184
? (context, value) =>

0 commit comments

Comments
 (0)