Hi there! Are you looking for the official Deno documentation? Try docs.deno.com for all your Deno learning needs.

switchAll

Converts a higher-order Observable into a first-order Observable producing values only from the most recent observable sequence

Flattens an Observable-of-Observables.

switchAll subscribes to a source that is an observable of observables, also known as a "higher-order observable" (or Observable<Observable<T>>). It subscribes to the most recently provided "inner observable" emitted by the source, unsubscribing from any previously subscribed to inner observable, such that only the most recent inner observable may be subscribed to at any point in time. The resulting observable returned by switchAll will only complete if the source observable completes, and any currently subscribed to inner observable also has completed, if there are any.

Examples

Spawn a new interval observable for each click event, but for every new click, cancel the previous interval and subscribe to the new one

import { fromEvent, tap, map, interval, switchAll } from 'rxjs';

const clicks = fromEvent(document, 'click').pipe(tap(() => console.log('click')));
const source = clicks.pipe(map(() => interval(1000)));

source
  .pipe(switchAll())
  .subscribe(x => console.log(x));

// Output
// click
// 0
// 1
// 2
// 3
// ...
// click
// 0
// 1
// 2
// ...
// click
// ...
function switchAll<O extends ObservableInput<any>>(): OperatorFunction<O, ObservedValueOf<O>>;
§
switchAll<O extends ObservableInput<any>>(): OperatorFunction<O, ObservedValueOf<O>>
[src]

§Type Parameters

§
O extends ObservableInput<any>
[src]

§Return Type

§

A function that returns an Observable that converts a higher-order Observable into a first-order Observable producing values only from the most recent Observable sequence.