mirror of
https://github.com/frappe/books.git
synced 2024-11-10 07:40:55 +00:00
20 lines
419 B
JavaScript
20 lines
419 B
JavaScript
|
module.exports = class Observable {
|
||
|
constructor() {
|
||
|
this._handlers = {};
|
||
|
}
|
||
|
|
||
|
on(event, fn) {
|
||
|
if (!this._handlers[event]) {
|
||
|
this._handlers[event] = [];
|
||
|
}
|
||
|
this._handlers[event].push(fn);
|
||
|
}
|
||
|
|
||
|
async trigger(event, params) {
|
||
|
if (this._handlers[event]) {
|
||
|
for (let handler of this._handlers[event]) {
|
||
|
await handler(params);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|