wishthis/node_modules/rxjs/internal/operators/audit.d.ts

49 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-05-29 09:24:36 +00:00
import { MonoTypeOperatorFunction, SubscribableOrPromise } from '../types';
2022-01-21 08:28:41 +00:00
/**
* Ignores source values for a duration determined by another Observable, then
* emits the most recent value from the source Observable, then repeats this
* process.
*
* <span class="informal">It's like {@link auditTime}, but the silencing
* duration is determined by a second Observable.</span>
*
2022-05-29 09:24:36 +00:00
* ![](audit.png)
2022-01-21 08:28:41 +00:00
*
* `audit` is similar to `throttle`, but emits the last value from the silenced
* time window, instead of the first value. `audit` emits the most recent value
* from the source Observable on the output Observable as soon as its internal
* timer becomes disabled, and ignores source values while the timer is enabled.
* Initially, the timer is disabled. As soon as the first source value arrives,
* the timer is enabled by calling the `durationSelector` function with the
* source value, which returns the "duration" Observable. When the duration
2022-05-29 09:24:36 +00:00
* Observable emits a value or completes, the timer is disabled, then the most
2022-01-21 08:28:41 +00:00
* recent source value is emitted on the output Observable, and this process
* repeats for the next source value.
*
* ## Example
*
* Emit clicks at a rate of at most one click per second
* ```ts
2022-05-29 09:24:36 +00:00
* import { fromEvent, interval } from 'rxjs';
* import { audit } from 'rxjs/operators'
2022-01-21 08:28:41 +00:00
*
* const clicks = fromEvent(document, 'click');
* const result = clicks.pipe(audit(ev => interval(1000)));
* result.subscribe(x => console.log(x));
* ```
* @see {@link auditTime}
* @see {@link debounce}
* @see {@link delayWhen}
* @see {@link sample}
* @see {@link throttle}
*
2022-05-29 09:24:36 +00:00
* @param {function(value: T): SubscribableOrPromise} durationSelector A function
2022-01-21 08:28:41 +00:00
* that receives a value from the source Observable, for computing the silencing
* duration, returned as an Observable or a Promise.
2022-05-29 09:24:36 +00:00
* @return {Observable<T>} An Observable that performs rate-limiting of
2022-01-21 08:28:41 +00:00
* emissions from the source Observable.
2022-05-29 09:24:36 +00:00
* @method audit
* @owner Observable
2022-01-21 08:28:41 +00:00
*/
2022-05-29 09:24:36 +00:00
export declare function audit<T>(durationSelector: (value: T) => SubscribableOrPromise<any>): MonoTypeOperatorFunction<T>;