2.0.0 • Published 9 years ago
@micro-js/reduce-map v2.0.0
reduce-map
Generates a reducing function that maps a reducer over the entities in a container (usually an object or array). That is complicated to state, but simple if you see the implementation:
function reduceMap (fn) {
return function (state, value) {
return map(iter, state)
function iter (item, key) {
return fn(item, value, key)
}
}
}
Installation
$ npm install @micro-js/reduce-map
Usage
var reduceMap = require('@micro-js/reduce-map')
combineActions({
todos: handleActions({
[SET_ALL_COMPLETED]: reduceMap((todo, {completed}) => ({...todo, completed}))
})
})
API
reduceMap(fn)
fn
- A function that accepts(item, value, key)
and produces a newitem
based onvalue
.
Returns: A reducing function that maps your reducer fn
, over state
to produce a new container of type state
from each of its elements, and the value passed to reduce.
License
MIT