Created
August 24, 2016 18:33
-
-
Save donabrams/c6932361bc63d888a545c5c1805724a4 to your computer and use it in GitHub Desktop.
Redux Reducer Middleware to Conditionally Execute a second action
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
import {createStore} from 'redux'; | |
import {interceptingAction} from 'redux-intercepting-action'; | |
import {createAction} from 'redux-actions'; | |
import reducer from './reducers' | |
const getInterceptingAction = (state)=> { | |
if (state.good) { | |
return { | |
type: 'YAY' | |
} | |
} | |
} | |
const store = createStore(interceptingAction(getInterceptingAction, reducer), initialState) |
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 function interceptingAction(getInterceptingAction, reduce) => (state, action) => { | |
const newState = reduce(state, action) | |
const secondAction = getInterceptingAction(newState) | |
return secondAction | |
? reduce(newState, secondAction) | |
: newState | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment