提交 ee717af0 编写于 作者: S Stephen Mathieson 提交者: 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.
上级 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% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册