Reducer Helpers
The following helpers are available for use with your saga slices. When used in combination with the other helpers, it makes development of new sagas much quicker.
readAllSuccess(state, payload)
readAllSuccess(state, payload)
Sets the
isFetching
state tofalse
.Maps the response payload into an object formatted like
{ [item.id]: item }
readOneSuccess(state, payload)
readOneSuccess(state, payload)
Sets the
isFetching
state tofalse
.Maps response to data by id
createSuccess(state, payload)
createSuccess(state, payload)
Sets the
isFetching
state tofalse
Maps response to data by id
updateSuccess(state, payload)
updateSuccess(state, payload)
Sets the
isFetching
state tofalse
.Maps response to data by id
deleteSuccess(state, payload)
deleteSuccess(state, payload)
Sets the
isFetching
state tofalse
.Deletes item from
data
failReducer(state, payload)
failReducer(state, payload)
Sets the
isFetching
state tofalse
.
loadingReducer(state, payload)
loadingReducer(state, payload)
Sets the
isFetching
state totrue
.
notLoadingReducer(state, payload)
notLoadingReducer(state, payload)
Sets the
isFetching
state to false.
setCurrent(state, payload)
setCurrent(state, payload)
If passed a number or string, sets
state.current
to an item instate.data
If passed an object, sets
state.current
topayload
resetCurrent(state, payload)
resetCurrent(state, payload)
Sets
state.current
tonull
crudInitialState(extendState)
crudInitialState(extendState)
Returns a state object structured to work with other helper functions. You can extend or overwrite the current state elements by passing an extended state. This function returns:
crudReducers(extend, doneReducers) => CrudReducerInstance
crudReducers(extend, doneReducers) => CrudReducerInstance
Generates a map of reducers for CRUD use
Can be extended or overwritten by passing
extend
optionDone reducers are created if
doneRecuders
is set to true
lifecycleReducers(name, reducers)
lifecycleReducers(name, reducers)
Creates a map of reducers specific to an ajax request lifecycle similar to what you see in
crudReducers
, but only for 1 method call.reducers
is an optional parameter. If the reducers are not specified, it will be provided a default. The reducers are overwritten usingmain
for the main action,success
for success action,fail
for fail action, anddone
can be a boolean or a function.
Example:
noop()
noop()
Does nothing. Used for declaring reducers.
Last updated