Function createReducer

  • Utility function to create reducers

    Returns

    a reducer function

    Example

    import { createEvent, createReducer } from 'reactive-actor';

    export interface LayoutState {
    loading: boolean;
    error: string;
    }

    export const layoutInitialState: LayoutState = {
    loading: false,
    error: '',
    };

    export const startLoader = createEvent('START_LOADER');

    export const stopLoader = createEvent('STOP_LOADER');

    export const layoutReducer = createReducer(layoutInitialState, (builder) =>
    builder
    .addCase(startLoader, (state) => ({ ...state, loading: true }))
    .addCase(stopLoader, (state) => ({ ...state, loading: false }))
    );

    Type Parameters

    Parameters

    • initialState: TState

      reducer initial state

    • builderFunction: BuilderFunction<TState>

      a function that takes an instance of ReducerBuilder<S> as parameter to generate the reducer

    Returns Reducer<TState, TEvent>

Generated using TypeDoc