Skip to main content
cngx-src documentation

tapAsyncState

Functioncommon/data/async-state

projects/common/data/async-state/operators.ts

Description#

RxJS operator that wires an Observable's lifecycle to a ManualAsyncState.

On subscribe: sets loading (or refreshing if data was already loaded). On next: calls setSuccess(value). On error: calls setError(err) and re-throws (does not swallow).

The Observable passes through unchanged — tapAsyncState is a side-effect operator.

readonly residents = createManualState<Resident[]>();

load(): void {
  this.http.get<Resident[]>('/api/residents').pipe(
    tapAsyncState(this.residents),
    takeUntilDestroyed(this.destroyRef),
  ).subscribe();
}

Signature#

tapAsyncState(state: AsyncStateSink, options?)

Parameters#

@paramstateAsyncStateSink
@paramoptions?

Returns#

MonoTypeOperatorFunction