Filtering Observables
These are the operators that selectively emit items from a given Observable based on a given condition/constraint.
The debounce operator
Emitting only after a specific timespan has passed can be done using these methods:
debounce
: Mirrors the initial Observable, except that it drops items emitted by the source that are followed by another item within a period of timethrottleWithTimeout
: Emits only those items that are not followed by another emitted item within a specified time window
In the following example, we'll drop items that are fired before our debounce timespan of 100 ms has passed; in our case it is just the last value managed. Again, by using the test scheduler, we advance the time:
The distinct operator
This removes distinct items emitted by an Observable using the following methods:
distinct
: Emits only distinct elementsdistinctUntilChanged
: Emits only elements that are distinct from their immediate predecessors
In the following code, we will see how to use the...