|
| 1 | + |
| 2 | +<br/><br/><br/> |
| 3 | + |
| 4 | +<a id="conditionalReducer"></a> |
| 5 | + |
| 6 | +<h5 style="margin: 10px 0px; border-width: 5px 0px; padding: 5px; border-style: solid;"> |
| 7 | + conditionalReducer(conditionalFn, thenReducerFn, [elseReducerFn], [initialState]) ⇒ [`reducerFn`](#reducerFn)</h5> |
| 8 | +Create a higher-order reducer that conditionally executes one ofthe supplied reducerFns, based on the conditionalFn() returndirective.The {{book.guide.devGuide}} discusses conditionalReducer() in more detail(see {{book.guide.conceptConditional}}), and additional examples canbe found in {{book.guide.conceptJoin}} and {{book.guide.fullExample}}. |
| 9 | + |
| 10 | + |
| 11 | +| Param | Type | Default | Description | |
| 12 | +| --- | --- | --- | --- | |
| 13 | +| conditionalFn | [`conditionalReducerCB`](#conditionalReducerCB) | | a callback function whose return value determines which reducerFn is executed ... truthy: thenReducerFn(), falsy: elseReducerFn(). | |
| 14 | +| thenReducerFn | [`reducerFn`](#reducerFn) | | the "wrapped" reducer invoked when conditionalFn returns truthy. | |
| 15 | +| [elseReducerFn] | [`reducerFn`](#reducerFn) | <code>identity</code> | the optional "wrapped" reducer invoked when conditionalFn returns falsy. DEFAULT: [identity function](https://lodash.com/docs#identity) | |
| 16 | +| [initialState] | [`InitialState`](#InitialState) | | the optional fall-back state value used during the state initialization boot-strap process. | |
| 17 | + |
| 18 | +**Returns**: [`reducerFn`](#reducerFn) - a newly created reducer function (described above). |
| 19 | + |
| 20 | +<br/><br/><br/> |
| 21 | + |
| 22 | +<a id="joinReducers"></a> |
| 23 | + |
| 24 | +<h5 style="margin: 10px 0px; border-width: 5px 0px; padding: 5px; border-style: solid;"> |
| 25 | + joinReducers(...reducerFns, [initialState]) ⇒ [`reducerFn`](#reducerFn)</h5> |
| 26 | +Create a higher-order reducer by combining two or more reducers,logically executing each in sequence (in essence combining theirfunctionality into one). This is useful when combining variousreducer types into one logical construct.**Please Note:** Because each reducer is able to build on what hasbeen accomplished by a prior reducer, joinReducers cumulativelypasses the state parameter that was returned from any prior reducer(in the chain of reducers to execute). In essence this is anaccumulative process. While this does NOT relax the immutableconstraint of the reducer's state parameter, it is possible for adown-stream reducer to receive a state parameter that is adifferent instance from the start of the reduction process (becausean up-stream reducer needed to alter it in some way).The {{book.guide.devGuide}} discusses joinReducers() in more detail(see {{book.guide.conceptJoin}}), and additional examples canbe found in {{book.guide.fullExample}}. |
| 27 | + |
| 28 | + |
| 29 | +| Param | Type | Description | |
| 30 | +| --- | --- | --- | |
| 31 | +| ...reducerFns | [`reducerFn`](#reducerFn) | two or more reducer functions to join together. | |
| 32 | +| [initialState] | [`InitialState`](#InitialState) | the optional fall-back state value used during the state initialization boot-strap process. | |
| 33 | + |
| 34 | +**Returns**: [`reducerFn`](#reducerFn) - a newly created reducer function (described above). |
| 35 | + |
| 36 | +<br/><br/><br/> |
| 37 | + |
| 38 | +<a id="reducerHash"></a> |
| 39 | + |
| 40 | +<h5 style="margin: 10px 0px; border-width: 5px 0px; padding: 5px; border-style: solid;"> |
| 41 | + reducerHash(actionHandlers, [initialState]) ⇒ [`reducerFn`](#reducerFn)</h5> |
| 42 | +Create a higher-order reducer by combining a set of sub-reducerfunctions that are indexed by the standard action.type. When noaction.type is acted on, the original state is merelypassed-through (using the [identityfunction](https://lodash.com/docs#identity)).This is one of the more prevalent composition reducers, andprovides an alternative to the switch statement (commonly used toprovide this control mechanism).The {{book.guide.devGuide}} discusses reducerHash() in more detail (see{{book.guide.conceptHash}}), and additional examples can be found in{{book.guide.conceptJoin}} and {{book.guide.fullExample}}.**SideBar**: Because reducerHash is so central to the rudimentaryaspect of reduction, it is a common practice to extend it,promoting a [`centralized reducer-based logging capability`](/extending/logExt.md), with an ability to correlate logging levels to state changes*(providing a means to filter logs at a high level with minimaloutput)*. |
| 43 | + |
| 44 | + |
| 45 | +| Param | Type | Description | |
| 46 | +| --- | --- | --- | |
| 47 | +| actionHandlers | [`ActionReducerHash`](#ActionReducerHash) | a hash of reducer functions, indexed by the standard redux action.type. | |
| 48 | +| [initialState] | [`InitialState`](#InitialState) | the optional fall-back state value used during the state initialization boot-strap process. | |
| 49 | + |
| 50 | +**Returns**: [`reducerFn`](#reducerFn) - a newly created reducer function (described above). |
| 51 | + |
| 52 | +<br/><br/><br/> |
| 53 | + |
| 54 | +<a id="conditionalReducerCB"></a> |
| 55 | + |
| 56 | +<h5 style="margin: 10px 0px; border-width: 5px 0px; padding: 5px; border-style: solid;"> |
| 57 | + conditionalReducerCB ⇒ truthy</h5> |
| 58 | +A callback function (used in {{book.api.conditionalReducer}}) whosereturn value determines which reducerFn is executed. |
| 59 | + |
| 60 | + |
| 61 | +| Param | Type | Description | |
| 62 | +| --- | --- | --- | |
| 63 | +| state | \* | The current immutable state that is the reduction target. | |
| 64 | +| action | [`Action`](#Action) | The standard redux Action object that drives the reduction process. | |
| 65 | +| 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 {{book.api.joinReducers}} ... because each individual reducer only has visibility of the state within it's own reduction process. Further information can be found in the {{book.guide.originalReducerState}} discussion of the {{book.guide.devGuide}}. | |
| 66 | + |
| 67 | +**Returns**: truthy - A truthy value indicating which reducerFn isexecuted ... truthy: thenReducerFn(), falsy: elseReducerFn(). |
| 68 | + |
| 69 | +<br/><br/><br/> |
| 70 | + |
| 71 | +<a id="ActionReducerHash"></a> |
| 72 | + |
| 73 | +<h5 style="margin: 10px 0px; border-width: 5px 0px; padding: 5px; border-style: solid;"> |
| 74 | + ActionReducerHash : Object</h5> |
| 75 | +A hash of reducer functions, indexed by the standard reduxaction.type. |
| 76 | + |
| 77 | +**Properties** |
| 78 | + |
| 79 | +| Name | Type | Description | |
| 80 | +| --- | --- | --- | |
| 81 | +| actionType1 | [`reducerFn`](#reducerFn) | The reducer function servicing: 'actionType1'. | |
| 82 | +| actionType2 | [`reducerFn`](#reducerFn) | The reducer function servicing: 'actionType2'. | |
| 83 | +| ...more | [`reducerFn`](#reducerFn) | ...etc. | |
| 84 | + |
| 85 | + |
| 86 | +<br/><br/><br/> |
| 87 | + |
| 88 | +<a id="reducerFn"></a> |
| 89 | + |
| 90 | +<h5 style="margin: 10px 0px; border-width: 5px 0px; padding: 5px; border-style: solid;"> |
| 91 | + reducerFn ⇒ \*</h5> |
| 92 | +A standard [redux reducer function](http://redux.js.org/docs/basics/Reducers.html)that is responsible for state changes. |
| 93 | + |
| 94 | + |
| 95 | +| Param | Type | Description | |
| 96 | +| --- | --- | --- | |
| 97 | +| state | \* | The current immutable state that is the reduction target. | |
| 98 | +| action | [`Action`](#Action) | The standard redux action which drives the reduction process. | |
| 99 | + |
| 100 | +**Returns**: \* - The resulting state after reduction. |
| 101 | + |
| 102 | +<br/><br/><br/> |
| 103 | + |
| 104 | +<a id="Action"></a> |
| 105 | + |
| 106 | +<h5 style="margin: 10px 0px; border-width: 5px 0px; padding: 5px; border-style: solid;"> |
| 107 | + Action : Object</h5> |
| 108 | +A standard [redux Action object](http://redux.js.org/docs/basics/Actions.html)that drives the reduction process. |
| 109 | + |
| 110 | +**Properties** |
| 111 | + |
| 112 | +| Name | Type | Description | |
| 113 | +| --- | --- | --- | |
| 114 | +| type | string | The action type. | |
| 115 | +| whatever | \* | Additional app-specific payload (as needed). | |
| 116 | + |
| 117 | + |
| 118 | +<br/><br/><br/> |
| 119 | + |
| 120 | +<a id="InitialState"></a> |
| 121 | + |
| 122 | +<h5 style="margin: 10px 0px; border-width: 5px 0px; padding: 5px; border-style: solid;"> |
| 123 | + InitialState : \*</h5> |
| 124 | +All astx-redux-util reducer creators, expose an `initialState`parameter which optionally provides a fall-back state value to useduring 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 thereduction entry point to each state element should define adefault. Keeping this in mind, the `initialState` parameter isoptional, because some reducers are "by design" (when combined in acomposition) intended to be mid-stream processors (i.e. NOT thereduction entry point). |
| 125 | + |
|
0 commit comments