mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
e2d98e4c26
Owl 2 will not have a router or store implemented inside the library
26 lines
875 B
Markdown
26 lines
875 B
Markdown
# 🦉 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.
|
|
|
|
```js
|
|
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 |
|