Service class for composing reducers and applying middleware to them.

Example


@Action
isLogin(state: Auth, action: AnyAction) {
state.isLoggedIn = true;
}

// or

@Action
isLogin(state: Auth, action: AnyAction) {
state.isLoggedIn = true;

return state;
}

//old-way
export function authReducer(state: Auth, action: AnyAction): Auth {
const newState = { ...state };
switch (action.type) {
case IS_LOGIN:
return { isLoggedIn: !state.isLoggedIn };
}

return state;
}

Hierarchy

  • ReducerService

Constructors

Properties

mapSubReducers: {
    [id: string]: Reducer;
} = {}

A mapSubReducers is a map of Reducers indexed by their hash signatures.

Type declaration

  • [id: string]: Reducer
rootReducer: Reducer

Holding current root reducer

Methods

  • Composes multiple reducers into a single reducer function and applies middleware to it.

    Returns

    • A new reducer function that applies the middleware chain to the root reducer.

    Parameters

    • rootReducer: Reducer

      The root reducer function to compose.

    • Optional middlewares: Middleware<any, AnyAction>[] = []

      An array of middleware functions to apply.

    Returns Reducer

  • Private

    Executes the middleware chain for the current action and returns the new state.

    Returns

    • The new state of the store after executing the middleware chain.

    Parameters

    • state: any

      The current state of the store.

    • action: AnyAction

      The current action being dispatched.

    • middlewareList: Middleware<any, AnyAction>[]

      An array of middlewares registered with the store.

    Returns any

  • Private

    Produces a new state object based on the given base state object and an action object. Uses a Proxy object to allow for "draft" modifications to the state object, and return the cleaned-up state object without any Proxy objects after the modifications have been made.

    Throws

    If the state is not object

    Returns

    The cleaned-up state object after the modifications have been made.

    Type Parameters

    • State extends object

      The type of the state object.

    Parameters

    • state: State

      The base state object to be modified.

    • action: any

      The action object to be applied to the state.

    • reducer: Reducer

      The reducer function that applies the action to the draft state.

    Returns any

  • Registers a local sub reducer with the Fractal Reducer Registry under the specified hash signature. If a reducer is already registered under the same hash signature, the new reducer is not added.

    Returns

    Parameters

    • hashReducer: number

      The hash signature of the reducer to be registered.

    • localReducer: Reducer

      The local reducer to be registered.

    Returns void

  • Replaces a registered sub-reducer with a new one based on the hash signature.

    Returns

    Parameters

    • hashReducer: number

      The hash signature of the registered sub-reducer.

    • nextLocalReducer: Reducer

      The new sub-reducer to replace the existing one.

    Returns void

  • Private

    The root reducer function for sub-stores.

    Returns

    If the sub-store state is not changed. If the sub-store state is changed, return the new state.

    Parameters

    • state: any

      The current state of the sub-store.

    • action: AnyAction

      The current action dispatched to the sub-store.

    • next: NextMiddleware<AnyAction>

      The next middleware to call.

    Returns AnyAction

Generated using TypeDoc