0.2.0 • Published 7 years ago

@morlay/redux-actions v0.2.0

Weekly downloads
1
License
WTFPL
Repository
github
Last release
7 years ago

redux actions

Enhancement for redux-actions

Build Status NPM Dependencies

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,
    }),
});