@tamagui/react-native-web-lite
Version:
React Native for Web
35 lines (34 loc) • 1.05 kB
JavaScript
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: !1 }) {
this._taskHandle && (this._taskHandle.cancel(), 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.js.map