update(value)

create.update create(actionType).update Appropriate leaf state: any

Returns a Riduce-standard action to update the leaf's state to value.

Parameters

Returns

action (object): a Riduce-standard action

Example

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)

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

Calling 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 }]

Calling 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 }]

Calling create.update on a branch:

const updateState = actions.create.update
store.dispatch(updateState({ any: { properties: true }}))
console.log(store.getState()) // { any: { properties: true } }