Class: StatefulComponent

StatefulComponent()

new StatefulComponent()

Properties:
Name Type Description
state Object
reducers Array.<function()>
actions Array.<Object>
previousStates Array.<Object>
snapshots Array.<Snapshot>
Source:

Methods

addReducer(fn)

Adds a reducer which will be called whenever an action is dispatched

Parameters:
Name Type Description
fn function
Source:

doAction(action, callbackopt, …callbackArgsopt)

Applies an action to the state, via the currently registered reducers.
If a reducer throws an error, it is caught and sent to onError

Once all reducers have been called, the action is pushed onto actions (to allow inspecting previous actions).

After everything, the callback is called, if provided

Parameters:
Name Type Attributes Description
action Object
callback function <optional>
callbackArgs any <optional>
<repeatable>
Source:

getPreviousState() → {Object|null}

Returns the update previous to the current one. If there was no previous state (e.g. there were no updates yet), returns null.

Source:
Returns:
Type
Object | null

onError(err)

Handles an error that came from a reducer. Default behavior is to throw the error, however
this can be overridden to allow other error handling.

Parameters:
Name Type Description
err Error
Source:

setState(newState, callbackopt)

Merges newState into state, then calls callback if provided.

Parameters:
Name Type Attributes Description
newState Object
callback function <optional>
Source: