Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SubReducer<TState, TReducerState>

SubReducer it's a class thats give acces to some additional functions to help build complicated reducers.

Type parameters

  • TState

  • TReducerState

Hierarchy

Implements

Index

Constructors

constructor

  • new SubReducer(name: string, initState?: Partial<TReducerState>): SubReducer
  • Initialize SubReducer class with given name (key) and [initState] Object that holds functions to manage subreducer, join reducers, on add per-action reducers, stateSelector select state controlled by reducer from app state, reducer getting reducer for connecting with redux.

    Parameters

    • name: string

      That argument is key in state object.

    • Optional initState: Partial<TReducerState>

      he initial state. You may optionally specify it to hydrate the state from the server in universal apps, or to restore a previously serialized user session. If you join another reducer, this must be a plain object with the same shape as the keys passed to it. Otherwise, you are free to pass anything that your reducer can understand.

    Returns SubReducer

Properties

Protected _name

_name: string

Private actionReducerList

actionReducerList: IActionReducerList<TReducerState>

Private initState

initState: Partial<TReducerState>

Private parent

parent: ISubReducer<any, TState>

Private reducers

reducers: Array<INamedReducer<any>>

Private subscribers

subscribers: Array<INamedSubscriber<any>>

Accessors

name

  • get name(): string

path

  • get path(): string

Methods

join

  • join<T>(reducer: ISubReducer<TReducerState, T>): this
  • Join subreducer to another. If subreducer with same name already joined, it will be unjoined before joining new.

    Type parameters

    • T: TReducerState[keyof TReducerState]

    Parameters

    Returns this

joinListener

  • joinListener(name: string, handler: function): this
  • Parameters

    • name: string
    • handler: function
        • (state: TState, action: any): void
        • Parameters

          • state: TState
          • action: any

          Returns void

    Returns this

joinReducer

  • joinReducer<T>(name: keyof TReducerState, reducer: function): this
  • Type parameters

    • T: TReducerState[keyof TReducerState]

    Parameters

    • name: keyof TReducerState
    • reducer: function
        • (state: T, action: any): T
        • Parameters

          • state: T
          • action: any

          Returns T

    Returns this

Private logActionInfo

on

reducer

  • reducer(state: TReducerState, action: A): any
  • Reducer function that reduce given state with action and returns new state. Also call each subscribers handler. If current state is function, call it with action as first argument and returns result. If current state and initState not a object (example string or number) pass state to ActionReducer and returns result. If current state is object reduce all joined ISubReducer (reducers) after pass state to ActionReducer and returns result.

    Parameters

    • state: TReducerState
    • action: A

    Returns any

setParent

stateSelector

  • stateSelector(state: any): any
  • Select subreducer controlled state from root state

    Parameters

    • state: any

      The state that you can get from store.getState()

    Returns any

Generated using TypeDoc