UNPKG

convex-pixel

Version:

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

43 lines 1.36 kB
import * as PIXI from "pixi.js"; import { SonarEventTypes } from "./sonar"; const DEFAULT_TIMEOUT = 500; export class SonarDebounce extends PIXI.utils.EventEmitter { constructor(timeout = DEFAULT_TIMEOUT, eventType = SonarEventTypes.CHANGE) { super(); this._detectChangesHandler = (nextStep = false) => { this.detectChanges(nextStep); }; this._timeout = timeout; this._eventType = eventType; } get eventType() { return this._eventType; } detectChanges(nextStep = false) { if (nextStep) { this._detectChangesNextFrame(); return; } if (!this._eventType) { throw Error("Property \"eventType\" is not defined."); } this.emit(this._eventType); } detect() { clearTimeout(this._timeoutId); this._timeoutId = setTimeout(this._detectChangesHandler, this._timeout); } stop() { clearTimeout(this._timeoutId); clearTimeout(this._nextTimeoutId); } destroy() { this.stop(); this.removeAllListeners(); } _detectChangesNextFrame() { clearTimeout(this._nextTimeoutId); this._nextTimeoutId = setTimeout(this._detectChangesHandler, 0); } } //# sourceMappingURL=sonar-debounce.js.map