Commit ee717af0 authored by Stephen Mathieson's avatar Stephen Mathieson Committed by Guillermo Rauch

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.
parent db50fc7d
......@@ -12,13 +12,15 @@ export const startClock = () => dispatch => {
return setInterval(() => dispatch({ type: 'TICK', light: true, ts: Date.now() }), 800)
}
let store = null
export const initStore = (reducer, initialState, isServer) => {
if (isServer && typeof window === 'undefined') {
return createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
} else {
if (!window.store) {
window.store = createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
if (!store) {
store = createStore(reducer, initialState, applyMiddleware(thunkMiddleware))
}
return window.store
return store
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment