Skip to content
Snippets Groups Projects

feat(plugins): Plugins Event Bus (MIN-225)

Merged mateusz-winiarczyk requested to merge MIN-225-events-bus into development
3 unresolved threads

It introduces plugins event bus for Minerva plugins, empowering them to seamlessly react to user interactions and application state alterations.

To listen for specific events, plugins can use the addListener method in events object returned by window.minerva.plugins.registerPlugin. This method takes two arguments: the name of the event and a callback function to handle the event. The types of possible events are described in the file docs/plugins.md

To remove event listener, plugins can use the removeListener method in events object returned by window.minerva.plugins.registerPlugin. This method takes two arguments: the name of the event and the reference to the callback function previously used to add the listener.

To remove all event listeners attached by a plugin, plugins can use the removeAllListeners method in events object returned by window.minerva.plugins.registerPlugin.

If you would like to learn how to implement a plugin with event listeners, you can find examples in docs/plugins.md to create your own plugin.

You can also use a plugin I created that has all the event listeners added. In the interface, you can remove the sample listener or all listeners by clicking the appropriate button: plugin link

events-bus

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
49 49 - configuration: includes information about available types of elements, reactions, miriam types, configuration options, map types and so on
50 50 - methods will be added in the future
51 51
52 ### Events
53
54 Plugins can interact with Minerva by subscribing to events. These events allow plugins to respond to user actions, system events, or changes in the application state.
55
56 #### Add Event Listener
  • 34 37 const handleOpenMap = (model: MapModel): void => {
    35 38 const modelId = model.idObject;
    36 39 const isMapOpened = checkIfMapAlreadyOpened(modelId);
    37
    40 if (currentMapModelId !== modelId) {
    41 PluginsEventBus.dispatchEvent('onSubmapClose', currentMapModelId);
    42 PluginsEventBus.dispatchEvent('onSubmapOpen', modelId);
    43 }
  • 28 34
    29 35 const onSubmapTabClick = (map: OppenedMap): void => {
    30 36 dispatch(setActiveMap(map));
    37 if (currentModelId !== map.modelId) {
    38 PluginsEventBus.dispatchEvent('onSubmapClose', currentModelId);
    39 PluginsEventBus.dispatchEvent('onSubmapOpen', map.modelId);
    40 }
  • LGTM. Great job!

  • Adrian Orłów approved this merge request

    approved this merge request

  • mateusz-winiarczyk added 21 commits

    added 21 commits

    • 8148e449...2553d2c1 - 18 commits from branch development
    • 67297866 - test(pluginseventbus): add tests for dispatching events
    • b02c8b59 - Merge remote-tracking branch 'origin/development' into MIN-225-events-bus
    • cd0ddbde - Merge remote-tracking branch 'origin/development' into MIN-225-events-bus

    Compare with previous version

  • mentioned in commit 6a321893

  • Please register or sign in to reply
    Loading