A function that returns an AsyncIterable. Generally, these are defined using async function*.
A type describing any function that returns a value that can be represented with an Observable (which is virtually anything).
This type is used as the constraint for the sole parameter of asyncLifecycle.
A union type representing all of the possible suffix values for {@link AsyncAction#type}.
The union type describing all possible states of an AsyncState.
The possible types for each field vary depending on status.
When collapsed, the type looks like:
type AsyncState<Data, Params> = {
status: null | 'active' | 'error' | 'completed'
params: null | Params
data: null | Data
error: null | unknown
}Note that the type of error is unknown when it is not null.
That is because, in JavaScript, a throw statement can throw a value of any type.
As such, the type of error cannot be inferred.
It must be narrowed using type guards before it can be used.
The possible values for {@link AsyncState#status}.
A function that returns an Observable.
A function that returns anything that can be converted to an Observable.
Signature of an event-like API for subscribing to Redux Actions. Used internally as a testing utility.
The type prefix applied to every AsyncAction.
Symbol used as a namespace for stately-async data on public objects.
A reducer that handles AsyncActions and updates the corresponding AsyncState. It is called by statelyAsyncReducer. Generally, you should not have to use this reducer directly.
Function extending Observable.from() defined by RxJS.
Adds support for conversion from Store<S> and AsyncIterable<S> (the type returned by TC39 "Async Generators").
See https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-3.html#async-iteration
Internal. Converts an AsyncIterable to an Observable by piping its yield into the subscriber until the AsyncIterable is exhausted.
Function that converts Store<S, A> -> SubjectLike<S, A>.
Given an Observable<Action>, returns a simple event-like API that can be used to register simple "handlers" for Redux actions.
Once registered, a handler will be called with the dispatched action(s) matching the given filter.
The optional onError parameter is called if an exception is thrown at any time, creating an error boundary to prevent cryptic failures.
Intended only as a utility for testing middleware. Do not use this in production.
Tip: Passing a Mocha.Done callback as the onError parameter will cause an exception thrown in the handler to fail the current test.
This way, this function can be used to make assertions about store state or component output based on an expected action.
See observables.spec.ts for an example.
Returns a Redux Middleware that pipes all dispatched actions through the given Subject.
Essentially, provides an indirect means to create an Observable<Action> from a Redux store.
Subscribers to the Subject are notified after the reducers are called, so can perform side-effects without delaying state updates.
This middleware can be used as a lightweight alternative to redux-observable.
Internal factory function that builds an AsyncActionCreator with the given lifecycle metadata and AsyncPhase.
The function defines how AsyncActions are created:
This information is useful to anyone who intends to define custom handling for AsyncActions, such as:
AsyncFunctions serially?)The public function asyncActionMatcher can be used by reducers or middleware to recognize and filter AsyncActions.
Factory that creates a configurable type guard for filtering and differentiating AsyncActions.
This function is useful to anyone who intends to define custom handling for AsyncActions, such as:
AsyncFunctions serially?)The returned guard will test a given action, returning true iff:
AsyncActiontype is given, or the action's saction matches the given typeoperation is given, or the action's infix matches the name of the given operationSee {@link createSessionActionCreator} for information about the internal structure of AsyncActions.
A factory function that creates an AsyncLifecycle for a given AsyncOperation.
Type guard to indicate whether a given action is an AsyncAction.
Type guard that indicates whether an object has the crucial methods to behave like a Redux Store.
Accepts an Observable<Action> and subscribes to it.
When an AsyncAction of type call is received, the epic triggers the corresponding AsyncOperation.
When the AsyncOperation emits data, encounters an error, or is completed, the 'data', 'error', and 'complete' actions are dispatched, respectively.
The function signature matches the Epic type from redux-observable, and is meant to be used with combineEpics if you are using redux-observable in your project.
If you are not using redux-observable, use statelyAsyncMiddleware instead.
Lightweight integration middleware, intended for projects that are not using redux-observable.
Serves as a direct store integration for statelyAsyncEpic.
A reducer that manages the AsyncSlice in the root of a state tree.
It maps actions by their uuid to individual AsyncLifecycle instances.
This reducer must be integrated into your Store for the library to work.
It is aliased and exported as statelyAsyncReducer from the library's index.
Generated using TypeDoc
stately-async
[api] [github]

This module contains types and functions for representing and managing the state of asynchronous operations. It is the underlying data API behind the
<Async>component instately-react.All asynchronous tasks have a similar lifecycle: they are called, data is emitted once or multiple times, and either the task is completed or an error is encountered. Typically, the code to manage this lifecycle is duplicated for every asynchronous action, whether it is done with epics, sagas, or component lifecycle.
This module provides functions and types that allow a consumer to use self-managing stateful "lifecycles" for arbitrary asynchronous tasks. A lifecycle can be created for any asynchronous function, regardless of its parameter arity, output type, or underlying implementation.
It is implemented following the action/reducer pattern, and is intended to work with Redux or any other state managment system that uses actions and reducers (such as
<Controllable>components.)Usage
Most asynchronous operations can be expressed declaratively using the
<Async>component, which is preferable to using this library directly. However, unusual or custom use cases may arise where it is ideal to create and use anAsyncLifecycledirectly:import store from './myStore' import getTweets from './getTweets' import { asyncLifecycle } from 'stately-async' class TweetsComponent extends React.Component { constructor(props) { super(props) this.tweetsLifecycle = asyncLifecycle(getTweets) } render() { const { state } = this.props return state.data ? <TweetsView tweets={state.data} /> : state.error ? <ErrorMessage error={state.error}> : state.status === 'active' ? <LoadingSpinner /> : null } componentDidMount() { store.dispatch(this.tweetsLifecycle.call('@myTwitterHandle')) } componentDidUnmount() { store.dispatch(this.tweetsLifecylce.destroy()) } }