path(path, value)
create.path
create(actionType).path
Appropriate leaf type: object
Returns an (action) object that the reduxLeaves reducer uses to non-mutatively set a property at path
from the leaf as value
.
Parameters
path
(string[]): an array of strings which represent the property path to set atvalue
(any): the value to set
Returns
action
(object): an object to dispatch to the store
Example
import { createStore } from 'redux'
import reduxLeaves from 'reduxLeaves'
const initialState = {
foo: {}
bar: { arbitrary: { keys: 3 } }
}
const [reducer, actions] = reduxLeaves(initialState)
const store = createStore(reducer)
Setting a new property
const setAtPathInFoo = actions.foo.create.path
store.dispatch(setAtPathInFoo(['nested', 'deep'], true))
console.log(store.getState().foo) // { nested: { deep: true } }
Overwriting a property
const setAtPathInBar = actions.bar.create("SET_AT_PATH_IN_BAR").path
store.dispatch(setAtPathInBar(['arbitrary', 'keys'], 5))
console.log(store.getState().bar) // { arbitrary: { keys: 5 } }