UNPKG

ih-black-lion

Version:

State handler for Arus projects

21 lines (19 loc) 739 B
/** * These are used throughout ./reducers */ export const toArray = arg => Array.isArray(arg) ? [...arg] : [arg]; export const initState = { isFetching: false, didInvalidate: false }; export const request = state => ({ ...state, isFetching: true }); export const invalidate = state => ({ ...state, didInvalidate: true }); export const receive = (state, action) => { const nextState = { data: action.response, isFetching: false, didInvalidate: false }; return { ...state, ...nextState }; }; export const receiveNested = (state, action) => { const nextState = { data: { ...state.data, ...{ [action.pageletName]: action.response } }, isFetching: false, didInvalidate: false, }; return { ...state, ...nextState }; };