Created
May 30, 2022 18:54
-
-
Save JanMalch/5f3fc24927cf8030ac773c8345f12deb to your computer and use it in GitHub Desktop.
Custom bufferDebounce RxJS operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { buffer, debounceTime, OperatorFunction, SchedulerLike } from 'rxjs'; | |
/** | |
* Emits buffered values from the source Observable only after a particular time span | |
* has passed without another source emission. | |
* | |
* @param {number} dueTime The timeout duration in milliseconds (or the time | |
* unit determined internally by the optional `scheduler`) for the window of | |
* time required to wait for emission silence before emitting the buffered | |
* source values. | |
* @param {SchedulerLike} scheduler The {@link SchedulerLike} to use for | |
* managing the timers that handle the timeout for each value. | |
* @author https://stackoverflow.com/a/62598663 | |
*/ | |
export function bufferDebounce<T>( | |
dueTime: number, | |
scheduler?: SchedulerLike, | |
): OperatorFunction<T, T[]> { | |
return (source) => | |
source.pipe(buffer(source.pipe(debounceTime(dueTime, scheduler)))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment