Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
themeConfluence
titleListening to Events dispatched to OpenSCD Core
export default class MyPlugin extends LitElement {
    fistUpdated() {
        this.getRootNode().addEventListener('oscd-event', () => { ... });
    }

}

In the code example above, the plugin listens to an OscdEvent dispatched by (for example) another plugin and is listening to this event via the common parent; Open-SCD Core.

  • Body
    • OpenSCD
      • Menu Plugin 1
      • Menu Plugin 2
      • Active Editor Plugin


Due to WebApi restrictions, Events that are emitted by one of the plugins are only bubbling up directly (https://www.freecodecamp.org/news/event-bubbling-in-javascript/)Find a (seperate solution) for all problems mentioned.


Pro's:

No new Code needs to be introduced


Con's:

This is only working for HTMLElements (Plugins).


Consequences

Implementing a central event-bus means that current OSCD plugins need some refactoring to dispatch events to the event-bus instead of dispatching events on itself.