January 2019
Beginner
210 pages
4h 47m
English
The throttle operator function can be used to reduce the number of values that are added to an observable:
import { fromEvent, interval } from "rxjs";import { throttle, mapTo, scan } from "rxjs/operators";const observable = fromEvent(document, "click") .pipe(mapTo(1)) .pipe(throttle(x => interval(100))) .pipe(scan((acc, one) => acc + one, 0));const subscription = observable.subscribe( (value) => console.log(value));subscription.unsubscribe();
The preceding code snippet creates an observable for click events. Every click will add an item to the sequence. The example also uses the pipe method and the mapTo function to map all the click events to the numeric value 1. It is then when we use the throttle operator to reduce the number ...
Read now
Unlock full access