filter(callback)
create.filter
create(actionType).filter
Appropriate leaf state: array
Returns a Riduce-standard action to non-mutatively update the leaf's state by selecting elements that return true when passed to callback
.
(Effectively, this uses the vanilla javascript Array.prototype.filter(callback)
API.)
callback
(function): the callback function to test each element withaction
(object): a Riduce-standard action
import { createStore } from 'redux'
import riduce from 'riduce'
const initialState = {
foo: [1, 2, 3, 4, 5],
bar: ['cat', 'dog', 'bat']
}
const [reducer, actions] = riduce(initialState)
const store = createStore(reducer)
const filterFoo = actions.foo.create.filter
store.dispatch(filterFoo(e => !(e % 2)))
console.log(store.getState().foo) // [2, 4]
const filterBar = actions.bar.create('FILTER_BAR').filter
store.dispatch(filterBar(e => e.includes('at')))
console.log(store.getState().bar) // ['cat', 'bat']