Reducer
Implements a registry for adding reducers, allowing them to be combined into a single reducing function. This reducing function is different from redux's combineReducers as it combines reducers recursively. Each reducer MUST be a function that takes in the arguments of the state and the action, and the reducer MUST return a valid state.
This object lives in the app as a singleton.
For testing purposes, The class that generates the singleton is exported. This is so that multiple copies of the reducer can be generated, making the unit tests independent of their execution order. In theory, this means that a developer can import this singleton's generating class and make their own reducer. Don't do this.
Static Method Summary
Static Public Methods | ||
public static |
root_reducer(state: Object, action: Object): Object In order to ensure that the reducer is always performing some action on the state, a function is added that simply returns the input state no matter what action is supplied to it. |
Constructor Summary
Public Constructor | ||
public |
Initialize the reducer to be a simple function that takes in the current state and returns this state. |
Method Summary
Public Methods | ||
public |
application_reducer(state: Object, action: Object): * The main reducer for the entire object. |
|
public |
register(callback: func) Push a callback onto this reducer's callback list |
Static Public Methods
public static root_reducer(state: Object, action: Object): Object source
In order to ensure that the reducer is always performing some action on the state, a function is added that simply returns the input state no matter what action is supplied to it.
Params:
Name | Type | Attribute | Description |
state | Object | The initial state that the root reducer will modify (or rather, will not modify) |
|
action | Object | A placeholder argument. Ordinarily, this would be an object containing all the necessary parameters to allow the application to change from the initial state to the intended final state. It does nothing in the root reducer, but an action must be passed in to preserve the (state, action) => (state) mapping. |
Public Constructors
public constructor source
Initialize the reducer to be a simple function that takes in the current state and returns this state.
Public Methods
public application_reducer(state: Object, action: Object): * source
The main reducer for the entire object. This function is executed by looping over all the callbacks in this object's callback list, and executing each callback with its required arguments. The only thing that should be calling this method is the reducer for the store when the store is created
Params:
Name | Type | Attribute | Description |
state | Object | The initial state that the application reducer will modify as a result of the action supplied. |
|
action | Object | An object containing a "type" property to signify what type of action it is, and which contains all the necessary parameters to effect the change from the initial state to the desired application state |
Return:
* |
public register(callback: func) source
Push a callback onto this reducer's callback list
Params:
Name | Type | Attribute | Description |
callback | func | The callback to add to the reducer. This must be a function that takes in the state and the action as arguments. |