UNPKG

ih-black-lion

Version:

State handler for Arus projects

34 lines (29 loc) 1.06 kB
# Redux Reducers To better understand reducers, it's advisable to read the [Redux Reducers docs](http://redux.js.org/docs/basics/Reducers.html). Many of our reducers take the form seen below ```js import { REQUEST_PROFILE, RECEIVE_PROFILE, INVALIDATE_PROFILE } from '../actionTypes'; // Normally the following consts are imported, as they are very common throughout all our reducers. const initState = { isFetching: false, didInvalidate: false }; const request = state => ({ ...state, isFetching: true }); const invalidate = state => ({ ...state, didInvalidate: true }); const receive = (state, action) => { const nextState = { data: action.response, isFetching: false, didInvalidate: false }; return { ...state, ...nextState }; }; export default function(state = initState, action) { switch (action.type) { case REQUEST_PROFILE: return request(state, action); case RECEIVE_PROFILE: return receive(state, action); case INVALIDATE_PROFILE: return invalidate(state, action); default: return state; } } ```