mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
examples/with-redux: remove global store (#908)
This patch removes the global `store` on the client. IMO this example should avoid polluting the global namespace with simple scoping tricks can solve the problem equally as well.
This commit is contained in:
parent
db50fc7dee
commit
ee717af088
|
@ -12,13 +12,15 @@ export const startClock = () => dispatch => {
|
||||||
return setInterval(() => dispatch({ type: 'TICK', light: true, ts: Date.now() }), 800)
|
return setInterval(() => dispatch({ type: 'TICK', light: true, ts: Date.now() }), 800)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let store = null
|
||||||
|
|
||||||
export const initStore = (reducer, initialState, isServer) => {
|
export const initStore = (reducer, initialState, isServer) => {
|
||||||
if (isServer && typeof window === 'undefined') {
|
if (isServer && typeof window === 'undefined') {
|
||||||
return createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
|
return createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
|
||||||
} else {
|
} else {
|
||||||
if (!window.store) {
|
if (!store) {
|
||||||
window.store = createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
|
store = createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
|
||||||
}
|
}
|
||||||
return window.store
|
return store
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue