@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in.
37 lines • 1.3 kB
JavaScript
import { getParam } from "./engine_utils.js";
const debug = getParam("debugcomponentevents");
export class ComponentLifecycleEvents {
static eventListeners = new Map();
static addComponentLifecylceEventListener(evt, cb) {
if (this.eventListeners.has(evt)) {
this.eventListeners.set(evt, []);
}
let arr = this.eventListeners.get(evt);
if (!arr)
arr = [];
arr.push(cb);
this.eventListeners.set(evt, arr);
if (debug)
console.log("Added event listener for " + evt, this.eventListeners);
}
static removeComponentLifecylceEventListener(evt, cb) {
const listeners = this.eventListeners.get(evt);
if (!listeners)
return;
const index = listeners.indexOf(cb);
if (index < 0)
return;
listeners.splice(index, 1);
}
static dispatchComponentLifecycleEvent(evt, data) {
const listeners = this.eventListeners.get(evt);
if (debug)
console.log("Dispatching event " + evt, listeners);
if (!listeners)
return;
for (const listener of listeners) {
listener(data);
}
}
}
//# sourceMappingURL=engine_components_internal.js.map