From c1335efe18469a1adb3dd442195a72d71201a6e6 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 1 Dec 2018 21:30:30 +0100 Subject: [PATCH] Allow array multiple callbacks per trigger --- Event/EventManager.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Event/EventManager.js b/Event/EventManager.js index f155e25..5782bbf 100644 --- a/Event/EventManager.js +++ b/Event/EventManager.js @@ -156,9 +156,14 @@ } if (!this.hasOutstanding(group)) { + const length = this.callbacks[group].callbacks.length; this.callbacks[group].lastRun = Date.now(); - this.callbacks[group].func(data); + for (let i = 0; i < length; ++i) { + this.callbacks[group].callbacks[i](data); + } + + // todo: only removes/resets if last func is remove/reset. this is messy, change if (this.callbacks[group].remove) { this.detach(group); } else if (this.callbacks[group].reset) { @@ -247,11 +252,11 @@ */ attach (group, callback, remove = false, reset = false) { - if (this.callbacks.hasOwnProperty(group)) { - return false; + if (!this.callbacks.hasOwnProperty(group)) { + this.callbacks[group] = {remove: remove, reset: reset, callbacks: [], lastRun: 0}; } - this.callbacks[group] = {remove: remove, reset: reset, func: callback, lastRun: 0}; + this.callbacks[group].callbacks.push(callback); return true; };