Skip to content

Commit 6bf3367

Browse files
Added module initial state.
1 parent 8de74d1 commit 6bf3367

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/bootstrap.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import configureStore from './configureStore'
44

55
export const BOOT = 'redux-boot/BOOT'
66

7-
export default function boot(initialState = {}, modules = []) {
8-
const {reducers, middlewares, enhancers} = processModules(modules)
7+
export default function boot(state = {}, modules = []) {
8+
const {reducers, middlewares, enhancers, initialState} = processModules(modules)
99

10-
let store = configureStore(initialState, reducers, middlewares, enhancers)
10+
state = Object.assign(initialState, state)
11+
12+
let store = configureStore(state, reducers, middlewares, enhancers)
1113

1214
return store
13-
.dispatch(bootAction(initialState))
14-
.then(action => {
15-
return {
16-
action,
17-
store
18-
}
19-
})
15+
.dispatch(bootAction(state))
16+
.then(action => ({
17+
action,
18+
store
19+
}))
2020
}
2121

2222
export const bootAction = createAction(BOOT, async initialState => initialState)

src/processModules.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ export default function processModules(modules) {
1515
.map(module => module.enhancer)
1616
.filter(enhancer => typeof enhancer == 'function')
1717

18+
const initialStates = modules.map(module => module.initialState || {})
19+
const initialState = initialStates.length ? Object.assign(...initialStates) : {}
20+
1821
return {
1922
reducers,
2023
middlewares,
2124
enhancers,
25+
initialState,
2226
}
2327
}
2428

0 commit comments

Comments
 (0)