UNPKG

@tamagui/react-native-web-lite

Version:
60 lines (59 loc) 2 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: !0 }); }, __copyProps = (to, from, except, desc) => { if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); return to; }; var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod); var Batchinator_exports = {}; __export(Batchinator_exports, { Batchinator: () => Batchinator, default: () => Batchinator_default }); module.exports = __toCommonJS(Batchinator_exports); var import_react_native_web_internals = require("@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 = import_react_native_web_internals.InteractionManager.runAfterInteractions(() => { this._taskHandle = null, this._callback(); }); }, this._delay); this._taskHandle = { cancel: () => clearTimeout(timeoutHandle) }; } } var Batchinator_default = Batchinator;