combineReducers
Turns two Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.
An example:
val reducer = combineReducers(
child(reducer1) { it.child1 },
child(reducer2) { it.child2 }
) { child1, child2 ->
State(child1, child2)
}
The example above is equivalent to:
val reducer = Reducer(
State(reducer1.initialState, reducer2.initialState)
) { acc, action ->
State(
reducer1.reduce(acc.child1, action),
reducer2.reduce(acc.child2, action),
)
)
This can also map parent actions to child actions. If the mapToChildAction]
returns null
, the child reducer will not be called.
val reducer = combineReducers(
child(
reducer1,
mapToChildAction = { it as? ParentAction.Child1 },
mapToChildState = { it.child1 }
),
child(
reducer2,
mapToChildAction = { it as? ParentAction.Child2 },
mapToChildState = { it.child2 }
)
) { child1, child2 ->
State(child1, child2)
}
Turns three Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.
Turns four Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.
Turns five Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.
Turns multiple Reducers into a single Reducer function. The resulting Reducer calls every child Reducer, and gathers their results into a single state object with the transform.