Skip to content

Commit

Permalink
Added module initial state.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasconstantino committed Jul 17, 2016
1 parent 8de74d1 commit 6bf3367
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import configureStore from './configureStore'

export const BOOT = 'redux-boot/BOOT'

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

let store = configureStore(initialState, reducers, middlewares, enhancers)
state = Object.assign(initialState, state)

let store = configureStore(state, reducers, middlewares, enhancers)

return store
.dispatch(bootAction(initialState))
.then(action => {
return {
action,
store
}
})
.dispatch(bootAction(state))
.then(action => ({
action,
store
}))
}

export const bootAction = createAction(BOOT, async initialState => initialState)
4 changes: 4 additions & 0 deletions src/processModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ export default function processModules(modules) {
.map(module => module.enhancer)
.filter(enhancer => typeof enhancer == 'function')

const initialStates = modules.map(module => module.initialState || {})
const initialState = initialStates.length ? Object.assign(...initialStates) : {}

return {
reducers,
middlewares,
enhancers,
initialState,
}
}

Expand Down

0 comments on commit 6bf3367

Please sign in to comment.