@micro-js/handle-actions
v1.0.3
Published
Compose a reducer from a map of action handlers
Downloads
4
Readme
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 @micro-js/handle-actions
Usage
var handleActions = require('@micro-js/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 ifstate
is undefined.
Returns: A composite reducer of the reducers in your map, scoped to their specified actions.
License
MIT