Skip to content

Commit

Permalink
examples/with-redux: remove global store (#908)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
stephenmathieson authored and rauchg committed Jan 28, 2017
1 parent db50fc7 commit ee717af
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions examples/with-redux/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

0 comments on commit ee717af

Please sign in to comment.