[DOC] event_bus: add initial doc

closes #157
This commit is contained in:
Géry Debongnie
2019-06-07 15:47:04 +02:00
parent 54c3dd76e4
commit f881640d3d
3 changed files with 29 additions and 1 deletions
+27
View File
@@ -0,0 +1,27 @@
# 🦉 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.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`](store.md) is an example of an `EventBus`.
+1
View File
@@ -7,6 +7,7 @@
- [QWeb](qweb.md)
- [Store](store.md)
- [Observer](observer.md)
- [Event Bus](event_bus.md)
- [Virtual DOM](vdom.md)
- [Utils](utils.md)
+1 -1
View File
@@ -63,7 +63,7 @@ store.dispatch('addTodo', 'fix all bugs');
## Reference
The store is a simple `owl.EventBus` that triggers `update` events whenever its
The store is a simple [`owl.EventBus`](event_bus.md) that triggers `update` events whenever its
state is changed. Note that these events are triggered only after a microtask
tick, so only one event will be triggered for any number of state changes in a
call stack.