UNPKG

@tamagui/react-native-web-lite

Version:
45 lines (44 loc) 1.13 kB
import { InteractionManager } from "@tamagui/react-native-web-internals"; class Batchinator { _callback; _delay; _taskHandle; constructor(callback, delayMS) { this._delay = delayMS; this._callback = callback; } /* * Cleanup any pending tasks. * * By default, if there is a pending task the callback is run immediately. Set the option abort to * true to not call the callback if it was pending. */ dispose(options = { abort: false }) { if (this._taskHandle) { this._taskHandle.cancel(); if (!options.abort) { this._callback(); } this._taskHandle = null; } } schedule() { if (this._taskHandle) { return; } const timeoutHandle = setTimeout(() => { this._taskHandle = InteractionManager.runAfterInteractions(() => { this._taskHandle = null; this._callback(); }); }, this._delay); this._taskHandle = { cancel: () => clearTimeout(timeoutHandle) }; } } var Batchinator_default = Batchinator; export { Batchinator, Batchinator_default as default }; //# sourceMappingURL=index.mjs.map