astx-redux-util

Methods

conditionalReducer(conditionalFn, thenReducerFn, elseReducerFnopt) → {reducerFn}

Source:

Create a higher-order reducer that conditionally executes one of the supplied reducerFns, based on the conditionalFn() return directive.

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

Parameters:
Name Type Attributes 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 <optional>
identity

the optional "wrapped" reducer invoked when conditionalFn returns falsy. DEFAULT: identity function

Returns:

a newly created reducer function (described above).

Type
reducerFn

joinReducers(…reducerFns) → {reducerFn}

Source:

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 User Guide discusses joinReducers() in more detail (see Joining Reducers), and additional examples can be found in A Most Excellent Example.

Parameters:
Name Type Attributes Description
reducerFns reducerFn <repeatable>

two or more reducer functions to join together.

Returns:

a newly created reducer function (described above).

Type
reducerFn

reducerHash(actionHandlers) → {reducerFn}

Source:

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 User Guide discusses reducerHash() in more detail (see Basics), and additional examples can be found in Joining Reducers and A Most Excellent Example.

NOTE: Because this function is so central to the rudimentary aspects of reduction, it is common to provide a value-added Logging Extension.

Parameters:
Name Type Description
actionHandlers ActionReducerHash

a hash of reducer functions, indexed by the standard redux action.type.

Returns:

a newly created reducer function (described above).

Type
reducerFn

Type Definitions

Action

Source:
Properties:
Name Type Description
type string | Symbol

The action type.

whatever *

Additional app-specific payload (as needed).

A standard redux Action object that drives the reduction process.

Type:
  • Object

ActionReducerHash

Source:
Properties:
Name Type Description
actionType1 reducerFn

The reducer function servicing: 'actionType1'.

actionType2 reducerFn

The reducer function servicing: 'actionType2'.

...more reducerFn

...etc.

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

Type:
  • Object

conditionalReducerCB(state, action, originalReducerState) → {truthy}

Source:

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

Parameters:
Name 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 User Guide.

Returns:

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

Type
truthy

reducerFn(state, action) → {*}

Source:

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

Parameters:
Name 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.

Type
*