silence error for emit

This commit is contained in:
atomiks
2018-01-06 00:30:47 +11:00
committed by GitHub
parent 39e096055a
commit 9af1e48ba9

View File

@ -14,7 +14,7 @@ For `off`, use `Array.findIndex()` to find the index of the handler in the event
const createEventHub = () => ({ const createEventHub = () => ({
hub: {}, hub: {},
emit(event, data) { emit(event, data) {
this.hub[event].forEach(handler => handler(data)); (this.hub[event] || []).forEach(handler => handler(data));
}, },
on(event, handler) { on(event, handler) {
if (!this.hub[event]) this.hub[event] = []; if (!this.hub[event]) this.hub[event] = [];