Options
All
  • Public
  • Public/Protected
  • All
Menu

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 allows new 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 the AsyncOperation is maintained. Dispatching the {@link AsyncLifecycle#call} action on a properly configured Store invokes the given AsyncOperation and begins a lifecycle. Any component subscribing to state changes can use the {@link AsyncLifecycle#selector} to access the AsyncState.

Actions dispatched from this object only affect the state of the owned AsyncState. The selector on this instance retrieves the managed AsyncState from the given root state.

Most consumers only need to use selector, call, and destroy. 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.

Type parameters

  • Data

  • Params: any[]

  • Data

  • Params: any[]

Hierarchy

  • AsyncLifecycle

Implements

Implemented by

Index

Constructors

constructor

Properties

call

call: AsyncActionCreator<Params>

Action creator that triggers the associated AsyncOperation when dispatched, passing any parameters directly through.

complete

complete: AsyncActionCreator<[]>

Action dispatched internally when the associated AsyncOperation completes (resolves, or emits all data in the case of an Observable or AsyncIterable).

data

data: AsyncActionCreator<[Data]>

Action dispatched internally when the associated AsyncOperation emits data.

destroy

destroy: AsyncActionCreator<[]>

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.

error

error: AsyncActionCreator<[any]>

Action dispatched internally when the associated AsyncOperation emits an error (rejects) or throws an exception.

id

id: string

The uuid of the AsyncState owned by this manager.

operation

operation: AsyncOperation<Data, Params>

The AsyncOperation given to {@link asyncSession}.

selector

selector: function

Returns the AsyncState instance owned by this manager.

Type declaration

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc