UNPKG

@polygonjs/polygonjs

Version:

node-based WebGL 3D engine https://polygonjs.com

61 lines (60 loc) 1.59 kB
"use strict"; export class EmitController { constructor(param) { this.param = param; this._blockedEmit = false; this._blockedParentEmit = false; this._countByEventName = /* @__PURE__ */ new Map(); } emitAllowed() { if (this._blockedEmit === true) { return false; } if (this.param.scene().loadingController.isLoading()) { return false; } return this.param.scene().dispatchController.emitAllowed(); } blockEmit() { this._blockedEmit = true; if (this.param.isMultiple() && this.param.components) { for (const component of this.param.components) { component.emitController.blockEmit(); } } return true; } unblockEmit() { this._blockedEmit = false; if (this.param.isMultiple() && this.param.components) { for (const component of this.param.components) { component.emitController.unblockEmit(); } } return true; } blockParentEmit() { this._blockedParentEmit = true; return true; } unblockParentEmit() { this._blockedParentEmit = false; return true; } incrementCount(eventName) { const count = (this._countByEventName.get(eventName) || 0) + 1; this._countByEventName.set(eventName, count); } eventsCount(eventName) { return this._countByEventName.get(eventName) || 0; } emit(event) { if (this.emitAllowed()) { this.param.emit(event); const parentParam = this.param.parentParam(); if (parentParam != null && this._blockedParentEmit !== true) { parentParam.emit(event); } } } }