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.)

Parameters

Returns

action (object): a Riduce-standard action

Example

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)

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']