@f/handle-actions

1.1.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i @f/handle-actions

Weekly Downloads

4

Version

1.1.2

License

MIT

Last publish

Collaborators

  • f