feat(plugins): Plugins Event Bus (MIN-225)
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
Merge request reports
Activity
assigned to @mateusz-winiarczyk
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 changed this line in version 2 of the diff
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 } added 21 commits
Toggle commit listmentioned in commit 6a321893