Created
May 16, 2017 14:39
-
-
Save ktabriga/00b2c7e3fdc6190b8e0a30d1cfa1755f 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
import {simplefyReducer, handleRemoveById, handleActionError, handleActionSuccess, handleAddTolist, startRequest, handleActionList, requestFinished} from '../utils' | |
import R from 'ramda' | |
const initialState = { | |
list: [], | |
fetching: false, | |
error: null | |
} | |
const addToList = (state, {error, payload}) => { | |
if (error) return handleActionError({state, payload}) | |
return R.compose( | |
handleAddTolist, | |
handleActionSuccess | |
)({state, payload}) | |
} | |
const updateResult = (state, {error, payload}) => { | |
if (error) return handleActionError({state, payload}) | |
return R.compose( | |
handleAddTolist, | |
handleRemoveById, | |
handleActionSuccess | |
)({state, payload}) | |
} | |
const receiveList = (state, {error, payload}) => { | |
if (error) return handleActionError({state, payload}) | |
return R.compose( | |
handleActionSuccess, | |
handleActionList | |
)({state, payload}) | |
} | |
const removeFromList = (state, {error, payload}) => { | |
if (error) return handleActionError({state, payload}) | |
return R.compose( | |
handleRemoveById, | |
handleActionSuccess | |
)({state, payload}) | |
} | |
export default simplefyReducer(initialState, { | |
CREATE_DISCIPULADO: startRequest, | |
FETCH_DISCIPULADO: startRequest, | |
FETCH_DISCIPULADO_LIST: startRequest, | |
REMOVE_DISCIPULADO: startRequest, | |
CREATE_DISCIPULADO_RESULT: addToList, | |
FETCH_DISCIPULADO_LIST_RESULT: receiveList, | |
FETCH_DISCIPULADO_RESULT: requestFinished, | |
REMOVE_DISCIPULADO_RESULT: removeFromList | |
}) | |
export const selectList = state => state.list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment