You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ignore source values for a duration determined by another Observable
then emit the most recent value from the source Observable
then repeat this process
var int$ = interval(1000);
var int_ = int$.pipe(
audit(it => interval(2000))
);
int_.subscribe(console.log);
TIME
1s
2s
3s
4s
5s
6s
7s
8s
9s
10s
11s
12s
13s
14s
15s
int_
2
5
8
11
14
// at most 1 click/second
const clicks = fromEvent(document, 'click');
const result = clicks.pipe(
audit(ev => interval(1000))
);
result.subscribe(console.log);
auditTime(durationMs)
// at most 1 click/second
const clicks = fromEvent(document, 'click');
const result = clicks.pipe(
auditTime(1000)
);
result.subscribe(console.log);
auditTime is similar to throttleTime, but emits the last value from the silenced time window, instead of the first value.
debounce(durationSelector)
Emits a value from the source Observable only after a particular time span has passed without another source emission.
// emit the most recent click after a burst of clicks
const clicks = fromEvent(document, 'click');
const result = clicks.pipe(
debounce(() => interval(1000))
);
result.subscribe(console.log);
debounceTime(dueTimeMs)
// emit the most recent click after a burst of clicks
const clicks = fromEvent(document, 'click');
const result = clicks.pipe(
debounceTime(1000)
);
result.subscribe(console.log);
fromEvent(document, 'click').pipe(
elementAt(2, 'nothing'),
take(2)
// take() is ignored even when reaching 5th element
).subscribe(console.log);
click
1st
2nd
3rd
4th
5th
obs.
Event
If the default value is not passed and the index is out of range, an ArgumentOutOfRangeError error will be emitted.
filter(predicate, thisArg?)
// emit only clicks on DIV elements
fromEvent(document, 'click')
.pipe(
// fn(value, index)
filter(e => e.target.tagName === 'DIV')
).subscribe(console.log);
first(predicate?, defaultValue?)
// emit the first click that happens on a DIV
fromEvent(document, 'click')
.pipe(
// fn(value, index, sourceObservable)
first(e => e.target.tagName === 'DIV')
).subscribe(console.log);
return an Observable that emits the single item emitted by the source Observable that matches a specified predicate, if that Observable emits one such item
if the source Observable emits more than one such item, notify of an IllegalArgumentException
if the source Observable emits no items, notify of an NoSuchElementException
if the source Observable emits items but none match the specified predicate then undefined is emitted
range(1, 5).pipe(single())
// error (sequence contains more than one element)
range(1, 5).pipe(single(x => x == 2))
// 2
range(1, 5).pipe(single(x => x == 10))
// undefined
of(1).pipe(single())
// 1
of().pipe(single())
// error [no elements in sequence]