rxjs/operators#debounce TypeScript Examples

The following examples show how to use rxjs/operators#debounce. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: debounce-with-backoff-while.ts    From js-client with MIT License 6 votes vote down vote up
debounceWithBackoffWhile = <T>({
	initialDueTime,
	step,
	maxDueTime,
	predicate,
}: {
	initialDueTime: number;
	step: number;
	maxDueTime: number;
	predicate: (value: T) => boolean;
}): MonoTypeOperatorFunction<T> => {
	const nextDueTime = (lastDueTime: number, value: T) => {
		if (!predicate(value)) {
			return initialDueTime;
		}
		return Math.min(lastDueTime + step, maxDueTime);
	};

	return (source: Observable<T>): Observable<T> =>
		source.pipe(debounce(rxjsDynamicDuration(nextDueTime, initialDueTime)));
}
Example #2
Source File: tour-backdrop.service.ts    From ngx-ui-tour with MIT License 6 votes vote down vote up
private subscribeToWindowResizeEvent() {
        const resizeObservable$ = fromEvent(window, 'resize');
        this.windowResizeSubscription$ = resizeObservable$
            .pipe(
                debounce(() => interval(10))
            )
            .subscribe(
                () => {
                    this.setBackdropElStyles();
                    ScrollingUtil.ensureVisible(this.targetHtmlElement);
                }
            );
    }