Files
owl/doc/event_bus.md
T
Géry Debongnie da1824f4dd [DOC] doc: improve navigation to main doc page
also, fixes a small error
2019-10-10 12:28:36 +02:00

941 B

🦉 Event Bus 🦉

It is sometimes useful to use a Bus to communicate informations between various parts of the code. Owl has a very simple bus class, which manages subscriptions, triggering events, and callbacks.

const bus = new owl.core.EventBus();

bus.on("some-event", null, function(...args) {
  console.log(...args);
});

bus.trigger("some-event", 1, 2, 3);
// [1,2,3] will be logged to the console

Its API is:

Method Description
on(eventType, owner, callback) add a listener
off(eventType, owner) remove all listeners for an owner
trigger(eventType, ...args) trigger an event
clear remove all subscriptions

Note that the Store is an example of an EventBus.