Created
October 13, 2016 14:03
-
-
Save lollotek/364ffa1875414e5629e161d45475fadf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
==== store.js ==== | |
const enhancers = [ | |
applyMiddleware(...middlewares), | |
devtools(), | |
testEnhancer(), | |
]; | |
===== pluginStateManager.js ===== | |
export const pluginStateManager = (state) => { | |
try { | |
// const serializedState = localStorage.getItem('state'); | |
// if (serializedState === null) { | |
// return undefined; | |
// } | |
// return JSON.parse(serializedState); | |
return state; | |
} catch (err) { | |
return undefined; | |
} | |
}; | |
export const testEnhancer = () => ( | |
(createStore) => (reducer, preloadedState, enhancer) => { | |
const store = createStore(reducer, preloadedState, enhancer); | |
const dispatch = (action) => { | |
// Swallow this action, and dispatch the replacement | |
if (action.type === 'SOME_ACTION_TYPE') { | |
store.dispatch({ | |
type: 'SOME_OTHER_ACTION_TYPE', | |
payload: 'some other payload', | |
}); | |
return null; | |
} | |
return store.dispatch(action); | |
}; | |
return Object.assign({}, store, { dispatch }); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment