conditionalReducer(conditionalFn, thenReducerFn, [elseReducerFn], [initialState]) ⇒ reducerFn
Create a higher-order reducer that conditionally executes one of the supplied reducerFns, based on the conditionalFn() return directive.

The Dev Guide discusses conditionalReducer() in more detail (see Conditional Reduction), and additional examples can be found in Joining Reducers and A Most Excellent Example.

Param Type Default Description
conditionalFn conditionalReducerCB a callback function whose return value determines which reducerFn is executed ... truthy: thenReducerFn(), falsy: elseReducerFn().
thenReducerFn reducerFn the "wrapped" reducer invoked when conditionalFn returns truthy.
[elseReducerFn] reducerFn identity the optional "wrapped" reducer invoked when conditionalFn returns falsy. DEFAULT: identity function
[initialState] InitialState the optional fall-back state value used during the state initialization boot-strap process.

Returns: reducerFn - a newly created reducer function (described above).




joinReducers(...reducerFns, [initialState]) ⇒ reducerFn
Create a higher-order reducer by combining two or more reducers, logically executing each in sequence (in essence combining their functionality into one). This is useful when combining various reducer types into one logical construct.

Please Note: Because each reducer is able to build on what has been accomplished by a prior reducer, joinReducers cumulatively passes the state parameter that was returned from any prior reducer (in the chain of reducers to execute). In essence this is an accumulative process. While this does NOT relax the immutable constraint of the reducer's state parameter, it is possible for a down-stream reducer to receive a state parameter that is a different instance from the start of the reduction process (because an up-stream reducer needed to alter it in some way).

The Dev Guide discusses joinReducers() in more detail (see Joining Reducers), and additional examples can be found in A Most Excellent Example.

Param Type Description
...reducerFns reducerFn two or more reducer functions to join together.
[initialState] InitialState the optional fall-back state value used during the state initialization boot-strap process.

Returns: reducerFn - a newly created reducer function (described above).




reducerHash(actionHandlers, [initialState]) ⇒ reducerFn
Create a higher-order reducer by combining a set of sub-reducer functions that are indexed by the standard action.type. When no action.type is acted on, the original state is merely passed-through (using the identity function).

This is one of the more prevalent composition reducers, and provides an alternative to the switch statement (commonly used to provide this control mechanism).

The Dev Guide discusses reducerHash() in more detail (see Basics), and additional examples can be found in Joining Reducers and A Most Excellent Example.

SideBar: Because reducerHash is so central to the rudimentary aspect of reduction, it is a common practice to extend it, promoting a centralized reducer-based logging capability, with an ability to correlate logging levels to state changes (providing a means to filter logs at a high level with minimal output).

Param Type Description
actionHandlers ActionReducerHash a hash of reducer functions, indexed by the standard redux action.type.
[initialState] InitialState the optional fall-back state value used during the state initialization boot-strap process.

Returns: reducerFn - a newly created reducer function (described above).




conditionalReducerCB ⇒ truthy
A callback function (used in conditionalReducer()) whose return value determines which reducerFn is executed.

Param Type Description
state * The current immutable state that is the reduction target.
action Action The standard redux Action object that drives the reduction process.
originalReducerState * The immutable state at the time of the start of the reduction process. This is useful in determining whether state has changed within a series of reductions joinReducers() ... because each individual reducer only has visibility of the state within it's own reduction process. Further information can be found in the originalReducerState discussion of the Dev Guide.

Returns: truthy - A truthy value indicating which reducerFn is executed ... truthy: thenReducerFn(), falsy: elseReducerFn().




ActionReducerHash : Object
A hash of reducer functions, indexed by the standard redux action.type.

Properties

Name Type Description
actionType1 reducerFn The reducer function servicing: 'actionType1'.
actionType2 reducerFn The reducer function servicing: 'actionType2'.
...more reducerFn ...etc.




reducerFn ⇒ *
A standard redux reducer function that is responsible for state changes.

Param Type Description
state * The current immutable state that is the reduction target.
action Action The standard redux action which drives the reduction process.

Returns: * - The resulting state after reduction.




Action : Object
A standard redux Action object that drives the reduction process.

Properties

Name Type Description
type string The action type.
whatever * Additional app-specific payload (as needed).




InitialState : *
All astx-redux-util reducer creators, expose an initialState parameter which optionally provides a fall-back state value to use during the state initialization boot-strap process.

In general, redux expects your state to have concrete values (i.e. something other than undefined). This means that the reduction entry point to each state element should define a default. Keeping this in mind, the initialState parameter is optional, because some reducers are "by design" (when combined in a composition) intended to be mid-stream processors (i.e. NOT the reduction entry point).

results matching ""

    No results matching ""