Action creator that triggers the associated AsyncOperation
when dispatched, passing any parameters directly through.
Action dispatched internally when the associated AsyncOperation
completes (resolves, or emits all data in the case of an Observable
or AsyncIterable
).
Action dispatched internally when the associated AsyncOperation
emits data.
Removes the AsyncState
instance owned by this AsyncLifecycle
from the state tree.
Failure to dispatch destroy
results in a memory leak, as AsyncState
objects remain in the state tree until they are destroyed, even if they are no longer being used.
For React components, a good practice is to dispatch the destroy
action in the component's componentWillUnmount
hook.
Action dispatched internally when the associated AsyncOperation
emits an error (rejects) or throws an exception.
The uuid of the AsyncState
owned by this manager.
The AsyncOperation
given to {@link asyncSession}.
Returns the AsyncState
instance owned by this manager.
Generated using TypeDoc
An object that provides a consistent, automated means to track loading, error, success, and data states for any AsyncOperation. This allows consumers - typically view components - to avoid duplicating ugly, error-prone side-effect branching logic and focus on rendering their declarative views.
Class
implementation of AsyncLifecycle. Basically just allowsnew AsyncLifecycle(operation)
, if you like that sort of thing.This is the primary export of
stately-async
.Each
AsyncLifecycle
is related to a unique AsyncState, where the current execution state of theAsyncOperation
is maintained. Dispatching the {@link AsyncLifecycle#call} action on a properly configured Store invokes the givenAsyncOperation
and begins a lifecycle. Any component subscribing to state changes can use the {@link AsyncLifecycle#selector} to access theAsyncState
.Actions dispatched from this object only affect the state of the owned
AsyncState
. Theselector
on this instance retrieves the managedAsyncState
from the given root state.Most consumers only need to use
selector
,call
, anddestroy
. Advanced use cases may leverage the additional action creators. Do not forget to dispatch {@link AsyncLifecycle#destroy} when the lifecycle is no longer needed. Failure to do so cause a memory leak.