2017-01-22 12:27:06 +00:00
|
|
|
import { createStore } from 'redux'
|
|
|
|
import getReducer from './reducer'
|
|
|
|
import createMiddleware from './middleware'
|
|
|
|
|
2017-01-28 16:22:32 +00:00
|
|
|
let reduxStore = null
|
|
|
|
|
2017-01-22 12:27:06 +00:00
|
|
|
export const initStore = (client, initialState) => {
|
|
|
|
let store
|
2017-01-28 16:22:32 +00:00
|
|
|
if (!process.browser || !reduxStore) {
|
2017-01-22 12:27:06 +00:00
|
|
|
const middleware = createMiddleware(client.middleware())
|
|
|
|
store = createStore(getReducer(client), initialState, middleware)
|
|
|
|
if (!process.browser) {
|
|
|
|
return store
|
|
|
|
}
|
2017-01-28 16:22:32 +00:00
|
|
|
reduxStore = store
|
2017-01-22 12:27:06 +00:00
|
|
|
}
|
2017-01-28 16:22:32 +00:00
|
|
|
return reduxStore
|
2017-01-22 12:27:06 +00:00
|
|
|
}
|