From: Mike Taylor Date: Tue, 4 Mar 2014 17:11:19 +0000 (+0000) Subject: Move event-queue code into teams. X-Git-Tag: 1.0.0~1331 X-Git-Url: http://jsfdemo.indexdata.com/?a=commitdiff_plain;h=f002c09b599b883add53eda5da0436072ab2b3ee;p=mkws-moved-to-github.git Move event-queue code into teams. Events are now subscribed/published on team-specific basis. As a result, we don't need the ugly faceted event names. --- diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index ee05520..1c19b2c 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -142,29 +142,6 @@ var mkws = { }; -// The following PubSub code is modified from the jQuery manual: -// https://api.jquery.com/jQuery.Callbacks/ -// -// Use as: -// mkws.queue("eventName").subscribe(function(param1, param2 ...) { ... }); -// mkws.queue("eventName").publish(arg1, arg2, ...); - -(function() { - var queues = {}; - mkws.queue = function(id) { - if (!queues[id]) { - var callbacks = $.Callbacks(); - queues[id] = { - publish: callbacks.fire, - subscribe: callbacks.add, - unsubscribe: callbacks.remove - }; - } - return queues[id]; - } -}()); - - // Define empty mkws_config for simple applications that don't define it. if (mkws_config == null || typeof mkws_config != 'object') { var mkws_config = {}; @@ -194,7 +171,7 @@ function widget($, team, type, node) { function promoteTargets() { - mkws.queue("targets." + team.name()).subscribe(function(data) { + team.queue("targets").subscribe(function(data) { if (node.length === 0) alert("huh?!"); var table ='' + @@ -221,7 +198,7 @@ function widget($, team, type, node) { function promoteStat() { - mkws.queue("stat." + team.name()).subscribe(function(data) { + team.queue("stat").subscribe(function(data) { if (node.length === 0) alert("huh?!"); $(node).html('' + M('Status info') + '' + @@ -307,13 +284,13 @@ function team($, teamName) { function onBytarget(data) { debug("target"); - mkws.queue("targets." + m_teamName).publish(data); + queue("targets").publish(data); } function onStat(data) { debug("stat"); - mkws.queue("stat." + m_teamName).publish(data); + queue("stat").publish(data); } @@ -1189,6 +1166,29 @@ function team($, teamName) { } + // The following PubSub code is modified from the jQuery manual: + // https://api.jquery.com/jQuery.Callbacks/ + // + // Use as: + // team.queue("eventName").subscribe(function(param1, param2 ...) { ... }); + // team.queue("eventName").publish(arg1, arg2, ...); + + var queues = {}; + var queue = function(id) { + if (!queues[id]) { + var callbacks = $.Callbacks(); + queues[id] = { + publish: callbacks.fire, + subscribe: callbacks.add, + unsubscribe: callbacks.remove + }; + } + return queues[id]; + } + + that.queue = queue; + + // main (function() { try {