From: Darren Date: Sun, 1 Jun 2014 11:18:30 +0000 (+0100) Subject: EventComponent comments X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=9b609554e86f6c084878155b2333366f10e376e0;p=KiwiIRC.git EventComponent comments --- diff --git a/client/src/app.js b/client/src/app.js index 748a28b..df454bc 100644 --- a/client/src/app.js +++ b/client/src/app.js @@ -28,8 +28,29 @@ _kiwi.global = { // Event managers for plugins components: { EventComponent: function(event_source, proxy_event_name) { + /* + * proxyEvent() listens for events then re-triggers them on its own + * event emitter. Why? So we can .off() on this emitter without + * effecting the source of events. Handy for plugins that we don't + * trust meddling with the core events. + * + * If listening for 'all' events the arguments are as follows: + * 1. Name of the triggered event + * 2. The event data + * For all other events, we only have one argument: + * 1. The event data + * + * When this is used via `new kiwi.components.Network()`, this listens + * for 'all' events so the first argument is the event name which is + * the connection ID. We don't want to re-trigger this event name so + * we need to juggle the arguments to find the real event name we want + * to emit. + */ function proxyEvent(event_name, event_data) { - if (proxy_event_name !== 'all') { + if (proxy_event_name == 'all') { + event_name = event_data.event_name; + event_data = event_data.event_data; + } else { event_data = event_name.event_data; event_name = event_name.event_name; }