mirror of
https://github.com/flarum/framework.git
synced 2025-05-23 07:09:57 +08:00
Replace Ember app with Mithril app
This commit is contained in:
36
js/lib/utils/evented.js
Normal file
36
js/lib/utils/evented.js
Normal file
@ -0,0 +1,36 @@
|
||||
export default {
|
||||
handlers: null,
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
getHandlers(event) {
|
||||
this.handlers = this.handlers || {};
|
||||
return this.handlers[event] = this.handlers[event] || [];
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
trigger(event, ...args) {
|
||||
this.getHandlers(event).forEach((handler) => handler.apply(this, args));
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
on(event, handler) {
|
||||
this.getHandlers(event).push(handler);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
*/
|
||||
off(event, handler) {
|
||||
var handlers = this.getHandlers(event);
|
||||
var index = handlers.indexOf(handler);
|
||||
if (index !== -1) {
|
||||
handlers.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user