[6a3a178] | 1 | import { MonoTypeOperatorFunction, SubscribableOrPromise } from '../types';
|
---|
| 2 | /**
|
---|
| 3 | * Ignores source values for a duration determined by another Observable, then
|
---|
| 4 | * emits the most recent value from the source Observable, then repeats this
|
---|
| 5 | * process.
|
---|
| 6 | *
|
---|
| 7 | * <span class="informal">It's like {@link auditTime}, but the silencing
|
---|
| 8 | * duration is determined by a second Observable.</span>
|
---|
| 9 | *
|
---|
| 10 | * ![](audit.png)
|
---|
| 11 | *
|
---|
| 12 | * `audit` is similar to `throttle`, but emits the last value from the silenced
|
---|
| 13 | * time window, instead of the first value. `audit` emits the most recent value
|
---|
| 14 | * from the source Observable on the output Observable as soon as its internal
|
---|
| 15 | * timer becomes disabled, and ignores source values while the timer is enabled.
|
---|
| 16 | * Initially, the timer is disabled. As soon as the first source value arrives,
|
---|
| 17 | * the timer is enabled by calling the `durationSelector` function with the
|
---|
| 18 | * source value, which returns the "duration" Observable. When the duration
|
---|
| 19 | * Observable emits a value or completes, the timer is disabled, then the most
|
---|
| 20 | * recent source value is emitted on the output Observable, and this process
|
---|
| 21 | * repeats for the next source value.
|
---|
| 22 | *
|
---|
| 23 | * ## Example
|
---|
| 24 | *
|
---|
| 25 | * Emit clicks at a rate of at most one click per second
|
---|
| 26 | * ```ts
|
---|
| 27 | * import { fromEvent, interval } from 'rxjs';
|
---|
| 28 | * import { audit } from 'rxjs/operators'
|
---|
| 29 | *
|
---|
| 30 | * const clicks = fromEvent(document, 'click');
|
---|
| 31 | * const result = clicks.pipe(audit(ev => interval(1000)));
|
---|
| 32 | * result.subscribe(x => console.log(x));
|
---|
| 33 | * ```
|
---|
| 34 | * @see {@link auditTime}
|
---|
| 35 | * @see {@link debounce}
|
---|
| 36 | * @see {@link delayWhen}
|
---|
| 37 | * @see {@link sample}
|
---|
| 38 | * @see {@link throttle}
|
---|
| 39 | *
|
---|
| 40 | * @param {function(value: T): SubscribableOrPromise} durationSelector A function
|
---|
| 41 | * that receives a value from the source Observable, for computing the silencing
|
---|
| 42 | * duration, returned as an Observable or a Promise.
|
---|
| 43 | * @return {Observable<T>} An Observable that performs rate-limiting of
|
---|
| 44 | * emissions from the source Observable.
|
---|
| 45 | * @method audit
|
---|
| 46 | * @owner Observable
|
---|
| 47 | */
|
---|
| 48 | export declare function audit<T>(durationSelector: (value: T) => SubscribableOrPromise<any>): MonoTypeOperatorFunction<T>;
|
---|