Last active
September 12, 2016 14:38
-
-
Save nihaux/578bd6d0654db97a578b284726a063b5 to your computer and use it in GitHub Desktop.
router5immutableReducer.js
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 { actionTypes } from 'redux-router5'; | |
import { Record } from 'immutable'; | |
// eslint-disable-next-line new-cap | |
const State = Record({ | |
route: null, | |
previousRoute: null, | |
transitionRoute: null, | |
transitionError: null, | |
}); | |
function router5Reducer(state = new State(), action) { | |
switch (action.type) { | |
case actionTypes.TRANSITION_START: | |
return state | |
.set('transitionRoute', action.payload.route) | |
.set('transitionError', null); | |
case actionTypes.TRANSITION_SUCCESS: | |
return state | |
.set('transitionRoute', null) | |
.set('transitionError', null) | |
.set('previousRoute', action.payload.previousRoute) | |
.set('route', action.payload.route); | |
case actionTypes.TRANSITION_ERROR: | |
return state | |
.set('transitionRoute', action.payload.route) | |
.set('transitionError', action.payload.transitionError); | |
case actionTypes.CLEAR_ERRORS: | |
return state | |
.set('transitionRoute', null) | |
.set('transitionError', null); | |
default: | |
return state; | |
} | |
} | |
export default router5Reducer; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment