filter(callback)
create.filter
create(actionType).filter
Appropriate leaf state: array
Returns an (action) object that the reduxLeaves reducer uses 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.)
Parameters
callback
(function): the callback function to test each element with
Returns
action
(object): an object to dispatch to the store
Example
import { createStore } from 'redux'
import reduxLeaves from 'reduxLeaves'
const initialState = {
foo: [1, 2, 3, 4, 5],
bar: ['cat', 'dog', 'bat']
}
const [reducer, actions] = reduxLeaves(initialState)
const store = createStore(reducer)
Calling create.filter
const filterFoo = actions.foo.create.filter
store.dispatch(filterFoo(e => !(e % 2)))
console.log(store.getState().foo) // [2, 4]
Calling create(actionType).filter
const filterBar = actions.bar.create('FILTER_BAR').filter
store.dispatch(filterBar(e => e.includes('at')))
console.log(store.getState().bar) // ['cat', 'bat']