e3230f8f21
Fixed broken build system in broken webpack version. Also updates module system to standardise on ES6 import/exports, Especially since babel has changed it's 'default' logic for the old module system.
28 lines
No EOL
757 B
JavaScript
28 lines
No EOL
757 B
JavaScript
/**
|
|
* Simple global events manager
|
|
*/
|
|
class Events {
|
|
constructor() {
|
|
this.listeners = {};
|
|
this.stack = [];
|
|
}
|
|
|
|
emit(eventName, eventData) {
|
|
this.stack.push({name: eventName, data: eventData});
|
|
if (typeof this.listeners[eventName] === 'undefined') return this;
|
|
let eventsToStart = this.listeners[eventName];
|
|
for (let i = 0; i < eventsToStart.length; i++) {
|
|
let event = eventsToStart[i];
|
|
event(eventData);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
listen(eventName, callback) {
|
|
if (typeof this.listeners[eventName] === 'undefined') this.listeners[eventName] = [];
|
|
this.listeners[eventName].push(callback);
|
|
return this;
|
|
}
|
|
}
|
|
|
|
export default Events; |