Overview
The EventBus is a simple pub/sub system that enables decoupled communication between plugins.
Methods
bus.on(event, callback)
Subscribe to an event. Multiple listeners can subscribe to the same event.
bus.off(event, callback)
Unsubscribe from an event. Must pass the same function reference used in on().
bus.once(event, callback)
Subscribe to an event, but the listener is automatically removed after the first emission.
bus.emit(event, data)
Publish an event to all subscribers. Errors in listeners are caught and logged without interrupting other listeners.
bus.removeAll([event])
Remove all listeners for a specific event, or all events if no event name is given.
removeAll() with no arguments is a nuclear option. Use with care — it removes listeners from every plugin, not just yours.
Naming Convention
Use namespace:action to avoid collisions between plugins:
Example: Cross-Plugin Communication
Plugins should never directly import or reference each other. Always use the event bus for communication.