From 0756f7e3e1f2ab76d23517832488a06b530a1e6b Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Fri, 14 Apr 2017 14:03:03 +0200 Subject: [PATCH] Restructure actions and events --- Event/EventManager.js | 4 ++-- UI/ActionManager.js | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/Event/EventManager.js b/Event/EventManager.js index 1b5d3ca..96a2ac7 100644 --- a/Event/EventManager.js +++ b/Event/EventManager.js @@ -113,7 +113,7 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.Event.EventManager.prototype.trigger = function (group, id) + jsOMS.Event.EventManager.prototype.trigger = function (group, id, data) { id = typeof id !== 'undefined' ? id : 0; @@ -126,7 +126,7 @@ } if (!this.hasOutstanding(group)) { - this.callbacks[group].func(); + this.callbacks[group].func(data); if (this.callbacks[group].remove) { this.detach(group); diff --git a/UI/ActionManager.js b/UI/ActionManager.js index 9ca81a9..8d7b3cd 100644 --- a/UI/ActionManager.js +++ b/UI/ActionManager.js @@ -75,10 +75,10 @@ actionLength = listeners[i].action.length; for (let j = 1; j < actionLength; j++) { - this.app.eventManager.attach(e.id + listeners[i].action[j - 1].type, function () + this.app.eventManager.attach(e.id + listeners[i].action[j - 1].type, function (data) { // todo: how to pass result from previous action to next action?! - self.runAction(e, listeners[i].action[j]); + self.runAction(e, listeners[i].action[j], data); }, false, true); // todo: handle onload action right after registering everything. this will be used for onload api calls in order to get content such as lists or models. Maybe in the main application after registering a invoke('onload') should be called if the application wants to execute the onload elements // todo: right now one event type can only exist once... needs fixing!!! @@ -104,21 +104,22 @@ * @since 1.0.0 * @author Dennis Eichhorn */ - jsOMS.UI.ActionManager.prototype.runAction = function (e, action) + jsOMS.UI.ActionManager.prototype.runAction = function (e, action, data) { const self = this; console.log(action.type); - console.log(this.actions); if (!this.actions.hasOwnProperty(action.type)) { console.log('Undefined action ' + action.type); return; } - this.actions[action.type](action, function () + action.data = data; + + this.actions[action.type](action, function (data) { - self.app.eventManager.trigger(e.id + action.type, e.id); + self.app.eventManager.trigger(e.id + action.type, e.id, data); }); };