@f/handle-actions

Compose a reducer from a map of action handlers

Stats

StarsIssuesVersionUpdatedCreatedSize
@f/handle-actions
201.1.26 years ago6 years agoMinified + gzip package size for @f/handle-actions in KB

Readme

handle-actions

Build status Git tag NPM version Code style

Compose a reducer from a map of action handlers. Very similar to handleActions in https://github.com/acdlite/redux-actions, but broken out as its own separate micro-module, and it also passes your handlers only action.payload. Note, this obviously assumes that you are using the flux standard action style, of type for the identifier and payload for the contents of your message. This means your reducers will be unable to examine any other fields (e.g. meta) - if you want to use other fields, don't use this module.

Installation

$ npm install @f/handle-actions

Usage

var handleActions = require('@f/handle-actions')

handleActions({
  UPDATE_ITEM: (state, changes) {
    // action.type === 'UPDATE_ITEM'
    return {
      ...state,
      ...changes
    }
  }
})

API

handleActions(map, defaultState)

  • map - Map of action types to handlers.
  • defaultState - Optional default state. This is returned if state is undefined.

Returns: A composite reducer of the reducers in your map, scoped to their specified actions.

License

MIT

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.