1.1.2 • Published 10 years ago
@f/handle-actions v1.1.2
handle-actions
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-actionsUsage
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 ifstateis undefined.
Returns: A composite reducer of the reducers in your map, scoped to their specified actions.
License
MIT