assign(...sources)
create.assign
create(actionType).assign
Returns an (action) object that the reduxLeaves reducer uses to non-mutatively copy all properties from sources
into the leaf's state.
(This is essentially a convenience wrapper on top of the vanilla JavaScript Object.assign
.)
Parameters
sources
(...objects): the path of the property to set
Returns
action
(object): an object to dispatch to the store
Example
import { createStore } from 'redux'
import reduxLeaves from 'reduxLeaves'
const initialState = {
foo: { props: true },
bar: { props: false }
}
const [reducer, actions] = reduxLeaves(initialState)
const store = createStore(reducer)
Assigning new properties
const assignToFoo = actions.foo.create.assign
store.dispatch(assignToFoo({ count: 2 }))
console.log(store.getState().foo) // { props: true, count: 2 }
Overwriting properties
const assignToBar = actions.bar.create.assign
store.dispatch(assignToBar({ props: true }))
console.log(store.getState().bar) // { props: true }