UNPKG

time-events-manager

Version:

View and Manage Javascript's timeout and interval collections

49 lines 2.02 kB
"use strict"; var override_1 = require('../overrides/override'); var IntervalCollection = (function () { function IntervalCollection() { this._intervalCollection = []; } IntervalCollection.prototype.add = function (handler, interval) { var args = []; for (var _i = 2; _i < arguments.length; _i++) { args[_i - 2] = arguments[_i]; } var id = override_1.originalSetInterval.apply(window, [handler, interval, args]); this._intervalCollection.push({ id: id, handler: handler, interval: interval, arguments: args, timestamp: Date.now() }); return id; }; IntervalCollection.prototype.remove = function (id) { var intervalIndex = this._getIntervalIndexById(id); if (intervalIndex !== -1) { this._intervalCollection.splice(intervalIndex, 1); } override_1.originalClearInterval.apply(window, [id]); }; IntervalCollection.prototype.get = function (index) { return this._intervalCollection[index]; }; IntervalCollection.prototype.getAll = function () { return this._intervalCollection; }; IntervalCollection.prototype.getById = function (id) { return this._intervalCollection[this._getIntervalIndexById(id)]; }; IntervalCollection.prototype.removeAll = function () { this._intervalCollection.forEach(function (interval) { override_1.originalClearInterval.apply(window, [interval.id]); }); this._intervalCollection = []; }; IntervalCollection.prototype._getIntervalIndexById = function (intervalId) { for (var i = 0; i < this._intervalCollection.length; i++) { if (this._intervalCollection[i].id === intervalId) { return i; } } return -1; }; return IntervalCollection; }()); exports.IntervalCollection = IntervalCollection; //# sourceMappingURL=interval-collection.model.js.map