Function: createReducer()
createReducer<
State
,Actions
>(reducerFactory
):ReducerFactory
<ActionFnsCreator
<Actions
>,WritableStateSource
<State
>>
Defined in: libs/ngrx-toolkit/src/lib/with-redux.ts:115
Creates a reducer function to separate the reducer logic into another file.
interface FlightState {
flights: Flight[];
effect1: boolean;
effect2: boolean;
}
const initialState: FlightState = {
flights: [],
effect1: false,
effect2: false,
};
const actions = {
init: noPayload,
updateEffect1: payload<{ value: boolean }>(),
updateEffect2: payload<{ value: boolean }>(),
};
const reducer = createReducer<FlightState, typeof actions>((actions, on) => {
on(actions.updateEffect1, (state, { value }) => {
patchState(state, { effect1: value });
});
on(actions.updateEffect2, (state, { value }) => {
patchState(state, { effect2: value });
});
});
signalStore(
withState(initialState),
withRedux({
actions,
reducer,
})
);
Type Parameters
• State extends object
• Actions extends ActionsFnSpecs
Parameters
reducerFactory
ReducerFactory
<ActionFnsCreator
<Actions
>, WritableStateSource
<State
>>
Returns
ReducerFactory
<ActionFnsCreator
<Actions
>, WritableStateSource
<State
>>