UNPKG

time-events-manager

Version:

View and Manage Javascript's timeout and interval collections

2 lines 5.05 kB
!function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var o=e();for(var n in o)("object"==typeof exports?exports:t)[n]=o[n]}}(this,function(){return function(t){function e(n){if(o[n])return o[n].exports;var i=o[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}var o={};return e.m=t,e.c=o,e.i=function(t){return t},e.d=function(t,o,n){e.o(t,o)||Object.defineProperty(t,o,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var o=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(o,"a",o),o},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=5)}([function(t,e,o){"use strict";e.originalSetTimeout=setTimeout,e.originalSetInterval=setInterval,e.originalClearInterval=clearInterval,e.originalClearTimeout=clearTimeout},function(t,e,o){"use strict";!function(t){t[t.Scheduled=0]="Scheduled",t[t.Completed=1]="Completed"}(e.TimeoutStatus||(e.TimeoutStatus={}));e.TimeoutStatus},function(t,e,o){"use strict";var n=o(4);e.intervalCollection=new n.IntervalCollection,window.setInterval=function(t,o){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];return e.intervalCollection.add(function(){t()},o,n)},window.clearInterval=function(t){e.intervalCollection.remove(t)}},function(t,e,o){"use strict";var n=o(6);e.timeoutCollection=new n.TimeoutCollection,window.setTimeout=function(t,o){for(var n=[],i=2;i<arguments.length;i++)n[i-2]=arguments[i];return e.timeoutCollection.add(t,o,n)},window.clearTimeout=function(t){e.timeoutCollection.remove(t)}},function(t,e,o){"use strict";var n=o(0),i=function(){function t(){this._intervalCollection=[]}return t.prototype.add=function(t,e){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];var r=n.originalSetInterval.apply(window,[t,e,o]);return this._intervalCollection.push({id:r,handler:t,interval:e,arguments:o,timestamp:Date.now()}),r},t.prototype.remove=function(t){var e=this._getIntervalIndexById(t);-1!==e&&this._intervalCollection.splice(e,1),n.originalClearInterval.apply(window,[t])},t.prototype.get=function(t){return this._intervalCollection[t]},t.prototype.getAll=function(){return this._intervalCollection},t.prototype.getById=function(t){return this._intervalCollection[this._getIntervalIndexById(t)]},t.prototype.removeAll=function(){this._intervalCollection.forEach(function(t){n.originalClearInterval.apply(window,[t.id])}),this._intervalCollection=[]},t.prototype._getIntervalIndexById=function(t){for(var e=0;e<this._intervalCollection.length;e++)if(this._intervalCollection[e].id===t)return e;return-1},t}();e.IntervalCollection=i},function(t,e,o){"use strict";function n(t){for(var o in t)e.hasOwnProperty(o)||(e[o]=t[o])}n(o(2)),n(o(3))},function(t,e,o){"use strict";var n=o(0),i=o(1),r=o(7),u=function(){function t(){this._timeoutCollection=[]}return t.prototype.add=function(t,e){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];var u=new r.Timeout(t,e,o),l=n.originalSetTimeout.apply(window,[this._getWrappedHandler(u.uuid,t),e,o]);return u.id=l,this._timeoutCollection.push(u),l},t.prototype.remove=function(t){var e=this._getTimeoutIndexById(t);-1!==e&&this._timeoutCollection.splice(e,1),n.originalClearTimeout.apply(window,[t])},t.prototype.get=function(t){return this._timeoutCollection[t]},t.prototype.getScheduled=function(){return this._timeoutCollection.filter(function(t){return t.status===i.TimeoutStatus.Scheduled})},t.prototype.getCompleted=function(){return this._timeoutCollection.filter(function(t){return t.status===i.TimeoutStatus.Completed})},t.prototype.getAll=function(){return this._timeoutCollection},t.prototype.getById=function(t){return this._timeoutCollection[this._getTimeoutIndexById(t)]},t.prototype.removeAll=function(){this._timeoutCollection.forEach(function(t){n.originalClearTimeout.apply(window,[t.id])}),this._timeoutCollection=[]},t.prototype._getWrappedHandler=function(t,e){var o=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r-0]=arguments[r];return o._timeoutCollection[o._getTimeoutIndexByUuid(t)].status=i.TimeoutStatus.Completed,e.apply(window,n)}},t.prototype._getTimeoutIndexById=function(t){for(var e=0;e<this._timeoutCollection.length;e++)if(this._timeoutCollection[e].id===t)return e;return-1},t.prototype._getTimeoutIndexByUuid=function(t){for(var e=0;e<this._timeoutCollection.length;e++)if(this._timeoutCollection[e].uuid===t)return e;return-1},t}();e.TimeoutCollection=u},function(t,e,o){"use strict";var n=o(1),i=function(){function t(t,e){for(var o=[],i=2;i<arguments.length;i++)o[i-2]=arguments[i];this.uuid=this._generateUuid(),this.handler=t,this.timeout=e,this.arguments=o,this.id=null,this.timestamp=Date.now(),this.status=n.TimeoutStatus.Scheduled}return t.prototype._generateUuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var e=16*Math.random()|0;return("x"==t?e:3&e|8).toString(16)})},t}();e.Timeout=i}])}); //# sourceMappingURL=main.min.js.map