Last active
February 5, 2018 19:09
-
-
Save debuggerpk/23b3c262831b921f239610ec3a5b4bf5 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
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