mirror of
https://github.com/Karaka-Management/jsOMS.git
synced 2026-02-15 16:58:42 +00:00
Allow array multiple callbacks per trigger
This commit is contained in:
parent
d0fb9f3255
commit
c1335efe18
|
|
@ -156,9 +156,14 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.hasOutstanding(group)) {
|
if (!this.hasOutstanding(group)) {
|
||||||
|
const length = this.callbacks[group].callbacks.length;
|
||||||
this.callbacks[group].lastRun = Date.now();
|
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) {
|
if (this.callbacks[group].remove) {
|
||||||
this.detach(group);
|
this.detach(group);
|
||||||
} else if (this.callbacks[group].reset) {
|
} else if (this.callbacks[group].reset) {
|
||||||
|
|
@ -247,11 +252,11 @@
|
||||||
*/
|
*/
|
||||||
attach (group, callback, remove = false, reset = false)
|
attach (group, callback, remove = false, reset = false)
|
||||||
{
|
{
|
||||||
if (this.callbacks.hasOwnProperty(group)) {
|
if (!this.callbacks.hasOwnProperty(group)) {
|
||||||
return false;
|
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;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user