UNPKG

convex-pixel

Version:

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

56 lines 2.11 kB
import { __extends } from "tslib"; import * as PIXI from "pixi.js"; import { SonarEventTypes } from "./sonar"; var DEFAULT_TIMEOUT = 500; var SonarDebounce = /** @class */ (function (_super) { __extends(SonarDebounce, _super); function SonarDebounce(timeout, eventType) { if (timeout === void 0) { timeout = DEFAULT_TIMEOUT; } if (eventType === void 0) { eventType = SonarEventTypes.CHANGE; } var _this = _super.call(this) || this; _this._detectChangesHandler = function (nextStep) { if (nextStep === void 0) { nextStep = false; } _this.detectChanges(nextStep); }; _this._timeout = timeout; _this._eventType = eventType; return _this; } Object.defineProperty(SonarDebounce.prototype, "eventType", { get: function () { return this._eventType; }, enumerable: true, configurable: true }); SonarDebounce.prototype.detectChanges = function (nextStep) { if (nextStep === void 0) { nextStep = false; } if (nextStep) { this._detectChangesNextFrame(); return; } if (!this._eventType) { throw Error("Property \"eventType\" is not defined."); } this.emit(this._eventType); }; SonarDebounce.prototype.detect = function () { clearTimeout(this._timeoutId); this._timeoutId = setTimeout(this._detectChangesHandler, this._timeout); }; SonarDebounce.prototype.stop = function () { clearTimeout(this._timeoutId); clearTimeout(this._nextTimeoutId); }; SonarDebounce.prototype.destroy = function () { this.stop(); this.removeAllListeners(); }; SonarDebounce.prototype._detectChangesNextFrame = function () { clearTimeout(this._nextTimeoutId); this._nextTimeoutId = setTimeout(this._detectChangesHandler, 0); }; return SonarDebounce; }(PIXI.utils.EventEmitter)); export { SonarDebounce }; //# sourceMappingURL=sonar-debounce.js.map