Any time you are calling create , you can pass an optional string argument to it. This will be the type
of any resulting action that gets created. (This does not change any reducer behaviour.)
If you are using bundle , you can pass a second argument of a string to control the type instead.
import riduce, { bundle } from 'riduce'
import { createStore } from 'redux'
const initialState = {
counter: 0,
nums: [4]
}
const double = (leafState: number) => 2 * leafState
const [reducer, actions] = riduce(initialState, { double })
const { getState, dispatch } = createStore(reducer)
const incrementCounter = actions.counter.create('INCREMENTED_COUNTER').increment(5)
incrementCounter.type // => 'INCREMENTED_COUNTER'
dispatch(incrementCounter)
getState().counter // => 5
const doubleCounter = actions.counter.create('DOUBLED_COUNTER').double()
doubleCounter.type // => 'DOUBLED_COUNTER'
dispatch(doubleCounter)
getState().counter // => 10
const storeCountThenDouble = bundle([
actions.nums.create.do((leafState, treeState) => [...leafState, treeState.counter]),
doubleCounter // bundle accepts any Riduce actions
], 'STORED_AND_DOUBLED')
storeCountThenDouble.type // => 'STORED AND DOUBLED'
dispatch(storeCountThenDouble)
getState() // => { counter: 20, nums: [4, 10] }