UNPKG

@lifaon/rx-js-light

Version:

Blazing fast Observables

22 lines (21 loc) 595 B
import {createAnimationFrame} from "../../../../../../misc/timer/create-animation-frame.mjs"; export function debounceFrameObservable(subscribe) { return emit => { let abortAnimationFrame = null; const unsubscribe = subscribe(value => { if (abortAnimationFrame !== null) { abortAnimationFrame(); } abortAnimationFrame = createAnimationFrame(() => { abortAnimationFrame = null; emit(value); }); }); return () => { unsubscribe(); if (abortAnimationFrame !== null) { abortAnimationFrame(); } }; }; }