2020-09-01 08:42:25 +00:00
|
|
|
|
|
|
|
export default class Notifications {
|
|
|
|
constructor() {
|
|
|
|
this._events = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
on(event, callback) {
|
2021-02-05 08:27:44 +00:00
|
|
|
const addevent = (e, c) => {
|
|
|
|
!this._events[e] && (this._events[e] = []);
|
|
|
|
this._events[e].push(c);
|
|
|
|
};
|
|
|
|
|
|
|
|
if ( typeof(event) == 'object' )
|
|
|
|
for (const i in event)
|
|
|
|
addevent(i, event[i])
|
|
|
|
else addevent(event, callback);
|
2020-09-01 08:42:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
off(event, callback) {
|
|
|
|
if ( this._events[event] && this._events[event].includes(callback) ) {
|
|
|
|
this._events[event].splice(this._events[event].indexOf(callback), 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
trigger(event/*, args*/) {
|
|
|
|
if ( this._events[event] ) {
|
|
|
|
this._events[event].forEach(callback => {
|
|
|
|
callback.apply(this, Array.prototype.slice.call(arguments, 1));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|