update(value)
create.update
create(actionType).update
Appropriate leaf state: any
Returns a Riduce-standard action to update the leaf's state to value
.
value
(any): the new value for the leaf's stateaction
(object): a Riduce-standard action
import { createStore } from 'redux'
import riduce from 'riduce'
const initialState = {
bool: false,
num: 2,
str: 'foo',
arr: [1, 2, { number: 3 }]
}
const [reducer, actions] = riduce(initialState)
const store = createStore(reducer)
create.update
on a leaf:const updateStr = actions.str.create.update
store.dispatch(updateStr("I can put anything here"))
console.log(store.getState().str) // 'I can put anything here'
create.update
on an array element:const updateFirstElementOfArr = actions.arr[1].create.update
store.dispatch(updateFirstElementOfArr('second'))
console.log(store.getState().arr) // [1, 'second', { number: 3 }]
create.update
within an array element:const updateSecondElementNumberProp = actions.arr[2].number.create.update
store.dispatch(updateSecondElementNumberProp(1337))
console.log(store.getState().arr) // [1, 'second', { number: 1337 }]
create.update
on a branch:const updateState = actions.create.update
store.dispatch(updateState({ any: { properties: true }}))
console.log(store.getState()) // { any: { properties: true } }