Options
All
  • Public
  • Public/Protected
  • All
Menu

Class ActionHandler<T>

This class represents an alternative to creating reducer functions with big and unwieldy switch statements. A new instance of this class is initialised with the initial state for the reducer. Following that, new action handler functions can be added via the addHandler() method, supplying action names a strings. Finally, a complete reducer function, which can be passed to combineReducers(), can be obtained by calling getReducer().

Type parameters

  • T

    Type of initial state

Hierarchy

  • ActionHandler

Index

Constructors

Properties

Methods

Constructors

constructor

  • Creates a new instance of the class using the given value as default initial state for the resulting reducer.

    Parameters

    • initialState: T

      Default initial state for the reducer

    Returns ActionHandler

Properties

Private handlers

handlers: Map<string, ActionHandlerFunction<T>>

Private initialState

initialState: T

Methods

addHandler

  • Add a new action handler function for the given action name. The function passed in receives the current state and action with potential payload as parameters.

    Parameters

    • action: string

      The name of the action corresponding to the reducer function

    • fn: ActionHandlerFunction<T>

      The function to be invoked in response to the given action.

    Returns void

getReducer

  • Returns a single reducer function, which is a combination of all handlers added through addHandler(). This resulting function can then be passed to combineReducers().

    Returns ReducerFunction<T>

    A single reducer function which combines all action handlers into one

Generated using TypeDoc