-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hub.js
66 lines (53 loc) · 1.81 KB
/
Hub.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(function (ns) {
"use strict";
/**
* @name wader.Hub
* @class Wader PubSub Hub
* @author Max Maximov <[email protected]>
* @version 0.3
*/
$.Class.extend("wader.Hub",
/** @lends wader.Hub */
{
_domNode: $("<i/>"),
/**
* @param {String} channel
* @param {*} data
* @return {undefined}
*/
pub: function (channel, data) {
data = data || {};
Logger.info("Publish to channel \"" + channel + "\"", data);
//Logger.info(this, "publish to channel \"" + channel + "\"", data);
this._domNode.trigger.apply(this._domNode, arguments);
},
/**
* @param {String} channel
* @param {Function} callback
* @return {undefined}
*/
sub: function (channel, callback) {
Logger.info("Subscribed to channel \"" + channel + "\"");
//Logger.info(this, "subscribed to channel \"" + channel + "\"");
function wrapper() {
return callback.apply(this, Array.prototype.slice.call(arguments, 1));
}
wrapper.guid = callback.guid = callback.guid || ($.guid ? $.guid++ : $.event.guid++);
this._domNode.bind(channel + ".wader", wrapper);
},
/**
* @param {String} channel
* @param {Function} callback
* @return {undefined}
*/
unsub: function (channel, callback) {
Logger.info("Unsubscribed from channel \"" + channel + "\"");
//Logger.info(this, "unsubscribed from channel \"" + channel + "\"");
this._domNode.unbind(channel + ".wader", callback);
}
},
/** @lends wader.Hub# */
{
});
if (ns !== wader) ns.Hub = wader.Hub;
})(window.WADER_NS || window);