Skip to content

Instantly share code, notes, and snippets.

@lollotek
Created October 13, 2016 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lollotek/364ffa1875414e5629e161d45475fadf to your computer and use it in GitHub Desktop.
Save lollotek/364ffa1875414e5629e161d45475fadf to your computer and use it in GitHub Desktop.
==== 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