UNPKG

convex-pixel

Version:

The library for creating pseudo 3d interactive scenes based on webgl

62 lines 2.21 kB
var DEFAULT_INTERVAL = 500; export var SonarEventTypes; (function (SonarEventTypes) { SonarEventTypes["CHANGE"] = "change"; SonarEventTypes["LOST_CONTEXT"] = "lost-context"; })(SonarEventTypes || (SonarEventTypes = {})); var Sonar = /** @class */ (function () { function Sonar(detectionInterval) { var _this = this; if (detectionInterval === void 0) { detectionInterval = DEFAULT_INTERVAL; } this._poolDetectors = new Array(); this._timerId = undefined; this._tickHandler = function () { for (var i = 0, l = _this._poolDetectors.length; i < l; i++) { _this._poolDetectors[i].detectChanges(); } }; this._interval = detectionInterval; } Sonar.create = function () { if (!Sonar.instance) { Sonar.instance = new Sonar(); } return Sonar.instance; }; Sonar.prototype.run = function () { this._timerId = setInterval(this._tickHandler, this._interval); }; Sonar.prototype.stop = function () { if (this._timerId) { clearInterval(this._timerId); this._timerId = undefined; } }; Sonar.prototype.add = function (detector) { if (this._poolDetectors.indexOf(detector) > -1) return; // throw new Error('The detector is already added to pool'); this._poolDetectors.push(detector); }; Sonar.prototype.remove = function (detector) { var index = this._poolDetectors.indexOf(detector); if (index === -1) return; // throw new Error('The detector is already removed'); this._poolDetectors.splice(index, 1); }; Sonar.prototype.removeAll = function () { while (this._poolDetectors.length > 0) { var detector = this._poolDetectors.pop(); if (detector) { detector.destroy(); } } }; Sonar.prototype.destroy = function () { this.stop(); this.removeAll(); this._poolDetectors.length = 0; }; return Sonar; }()); export { Sonar }; //# sourceMappingURL=sonar.js.map