@morlay/redux-actions
v0.2.0
Published
Enhancement for `redux-actions`
Downloads
7
Readme
redux actions
Enhancement for redux-actions
APIs
createAction(type, payloadCreator = Identity, ?metaCreator)
Usage like redux-actions#createAction
but will overwrite .toString()
to the actionCreator,
toString()
will return actionType
handleActions(reducerMap, ?defaultState)
Usage like redux-actions#handleActions
,
but callback of handler will be (state, payload, meta) => ()
instead of (state, action)
buildCreateAction(actionStatusTypes): createAction
for build multiple status action creator
Examples
import {
buildCreateAction,
createAction,
handleActions,
} from '@morlay/redux-actions';
const createMultiAction = buildCreateAction({
success: (type) => `${type}_SUCCESS`,
failed: (type) => `${type}_FAILED`,
});
const syncAction = createAction('syncAction');
const asyncAction = createMultiAction('asyncAction');
const reducer = handleActions({
[syncAction]: ({ counter }, payload) => ({
counter: payload,
}),
[asyncAction.success]: ({ counter }, payload) => ({
counter: counter + payload,
}),
});