new GlobalEvents()
Creates a central event manager for publishing global framework events.
This global object is the key mechanism for ensuring that the NLB Framework is kept entirely independent of and isolated from the front-end user interface (UI) framework. It allows frameworks such as Vue, React, Preact, Angular, Enyo, Ember, Knockout or any other to subscribe to global events and handle them in any way they wish without the NLB Framework needing to know anything about how or when that is done.
Whilst modern UI frameworks no longer pose the same kinds of risk, some frameworks are/were quite invasive when adding observability or reactivity to objects, sometimes recursing down many levels and actually modifying properties or the objects themselves. Using pub/sub message passing is a way to try to minimise the risk of this kind of unwanted 'leakage' of reactivity or observability into the actual BIM model.
Details
This class uses a slightly modified version of the event dispatch pattern used
in THREE.js to propagate events between the NLB Framework, UI and elements within
the model. The key difference from THREE.js is that the framework uses a custom
dispatch(type, ...args) method rather than the dispatchEvent(event) method
defined in THREE.EventDispatcher.
This extended method does not require a bespoke object for storing each event's properties so that it can be passed as a single argument to each listener. Rather, the extended method passes all of the additional arguments given in the dispatch method call on to each of the event handlers. It also returns a boolean indicating whether or not there were any handlers called for that event.
This makes the message passing a bit more flexible as it allows custom classes to generate their own custom events without having to create and/or register a bespoke event object. As a result, only that custom class (and any related classes) needs to know anything about the event type and what arguments to expect.
NOTE: It is important to use a unique prefix (other than '!pd-' used by core events) for your custom event names in order to prevent them conflicting with custom events that may be generated by other user-defined classes.