async-tick
Version:
2 lines • 1.46 kB
JavaScript
var t={d:(e,o)=>{for(var r in o)t.o(o,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:o[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};t.d(e,{Ds:()=>r,gJ:()=>s,P2:()=>c});class o{start(t){this.callback=t,this.started||(this.started=!0,this.create())}create(){if("function"!=typeof window.queueMicrotask){if("function"!=typeof Promise)throw new Error("Current browser does NOT support queueMicrotask or Promise");Promise.resolve().then((()=>{this.execute()}))}else window.queueMicrotask((()=>{this.execute()}))}execute(){if(!this.started)return;this.started=!1;const t=this.callback;this.callback=null,"function"==typeof t&&t.call(this)}cancel(){this.started=!1,this.callback=null}}const r=function(t){let e,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100;const r=function(){clearTimeout(e),e=setTimeout((()=>{t.apply(this,arguments)}),o)};return r.cancel=()=>{clearTimeout(e)},r},c=function(t){let e,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:100,r=0;const c=function(){const c=Date.now();if(c>r+o)return clearTimeout(e),r=c,void t.apply(this,arguments);clearTimeout(e),e=setTimeout((()=>{r=c,t.apply(this,arguments)}),o)};return c.cancel=()=>{clearTimeout(e),r=0},c},s=function(t){const e=new o,r=function(){e.start((()=>{t.apply(this,arguments)}))};return r.cancel=()=>{e.cancel()},r};var i=e.Ds,n=e.gJ,a=e.P2;export{i as debounce,n as microtask,a as throttle};
//# sourceMappingURL=async-tick.esm.js.map