azure-devops-ui
Version:
React components for building web UI in Azure DevOps
1 lines • 3.35 kB
JavaScript
import{__spreadArray}from"tslib";var TimerManagement=function(){function t(t){this.disposed=!1,this.immediateIds=null,this.intervals=[],this.timeouts=[],this.parent=t||null}return t.prototype.clearAllTimers=function(){for(var t=0,e=this.intervals;t<e.length;t++){var i=e[t];window.clearInterval(i)}for(var n=0,r=this.timeouts;n<r.length;n++){var o=r[n];window.clearTimeout(o)}this.intervals.splice(0,this.intervals.length),this.timeouts.splice(0,this.timeouts.length)},t.prototype.clearImmediate=function(t){this.immediateIds&&this.immediateIds[t]&&(window.clearTimeout(t),delete this.immediateIds[t])},t.prototype.clearInterval=function(t){window.clearInterval(t),this.removeInterval(t)},t.prototype.clearTimeout=function(t){window.clearTimeout(t),this.removeTimeout(t)},t.prototype.setImmediate=function(t){var e=this,i=0;return this.disposed||(this.immediateIds||(this.immediateIds={}),i=window.setTimeout(function(){try{e.immediateIds&&delete e.immediateIds[i],t.apply(e.parent)}catch(t){}},0),this.immediateIds[i]=!0),i},t.prototype.setInterval=function(t,e){for(var i=[],n=2;n<arguments.length;n++)i[n-2]=arguments[n];var r=window.setInterval.apply(window,__spreadArray([t,e],i,!1));return this.intervals.push(r),r},t.prototype.setTimeout=function(t,e){for(var i=this,n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];var o=0,o=window.setTimeout.apply(window,__spreadArray([function(){i.removeTimeout(o),t.apply(void 0,n)},e],n,!1));return this.timeouts.push(o),o},t.prototype.dispose=function(){if(this.disposed=!0,this.parent=null,this.clearAllTimers(),this.immediateIds)for(var t in this.immediateIds)this.immediateIds.hasOwnProperty(t)&&this.clearImmediate(parseInt(t,10));this.immediateIds=null},t.prototype.debounce=function(e,t,i){var a,l,u,m,d,p,c,n,h,r,f,v,o,s,w=this;return this.disposed?((s=function(){}).cancel=function(){},s.flush=function(){return null},s.pending=function(){return!1}):(a=t||0,u=!(l=!1),m=null,d=0,p=(new Date).getTime(),h=null,i&&(l=i.leading||!1,u=i.trailing||!0,m=i.maxWait||null),r=function(t){h&&(w.clearTimeout(h),h=null),p=t},f=function(t){r(t),c=e.apply(null,n)},v=function(t){var e=(new Date).getTime(),i=!1,n=(t&&(l&&a<=e-d&&(i=!0),d=e),e-d),r=a-n,o=e-p,s=!1;return null!==m&&(m<=o&&h?s=!0:r=Math.min(r,m-o)),a<=n||s||i?f(e):null!==h&&t||!u||(h=w.setTimeout(v,r)),c},o=function(){return!!h},(s=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return n=t,v(!0)}).cancel=function(){o()&&r((new Date).getTime())},s.flush=function(){return o()&&f((new Date).getTime()),c},s.pending=o),s},t.prototype.throttle=function(r,t,e){var i,o,s,a,l,u,m,d,p,c=this;return this.disposed?((i=function(){}).cancel=function(){},i.flush=function(){return null},i.pending=function(){return!1},i):(o=t||0,a=s=!0,l=0,d=null,e&&"boolean"==typeof e.leading&&(s=e.leading),e&&"boolean"==typeof e.trailing&&(a=e.trailing),p=function(t){var e=(new Date).getTime(),i=e-l,n=s?o-i:o;return o<=i&&(!t||s)?(l=e,d&&(c.clearTimeout(d),d=null),u=r.apply(null,m)):null===d&&a&&(d=c.setTimeout(p,n)),u},function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return m=t,p(!0)})},t.prototype.removeInterval=function(t){t=this.intervals.indexOf(t);0<=t&&this.intervals.splice(t,1)},t.prototype.removeTimeout=function(t){t=this.timeouts.indexOf(t);0<=t&&this.timeouts.splice(t,1)},t}();export{TimerManagement};