Skip to content

Instantly share code, notes, and snippets.

@debuggerpk
Last active February 5, 2018 19:09
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 debuggerpk/23b3c262831b921f239610ec3a5b4bf5 to your computer and use it in GitHub Desktop.
Save debuggerpk/23b3c262831b921f239610ec3a5b4bf5 to your computer and use it in GitHub Desktop.
export const actionToPlainObjectMiddleware = store => next => action => {
if (typeof action === 'object' && action.type) {
const toForward = { ...action };
return next(toForward);
} else if (typeof action === 'function') {
let toForward = action();
toForward = { ...toForward };
return next(toForward);
} else {
throw new Error('Action must be FSA');
}
};
// Just as an FYI, This is how I am dispatching the first action
store.dispatch(new windowActions.LoadWindowStateFromStorage());
// And this is how my store is setup
const epicsMiddleware = createEpicMiddleware(windowEpics);
export const store = createStore(
windowStateReducer,
applyMiddleware(actionToPlainObjectMiddleware, epicsMiddleware),
);
replayActionMain(store);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment