forked from bitovi/jquerypp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubscribe.js
More file actions
54 lines (52 loc) · 1.67 KB
/
subscribe.js
File metadata and controls
54 lines (52 loc) · 1.67 KB
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
/*global OpenAjax: true */
steal('jquerypp/controller', 'jquerypp/lang/openajax').then(function() {
/**
* @function jQuery.Controller.static.processors.subscribe
* @parent jQuery.Controller.static.processors
* @plugin jquerypp/controller/subscribe
* Adds OpenAjax.Hub subscribing to controllers.
*
* $.Controller("Subscriber",{
* "recipe.updated subscribe" : function(called, recipe){
*
* },
* "todo.* subscribe" : function(called, todo){
*
* }
* })
*
* You should typically be listening to jQuery triggered events when communicating between
* controllers. Subscribe should be used for listening to model changes.
*
* ### API
*
* This is the call signiture for the processor, not the controller subscription callbacks.
*
* @param {HTMLElement} el the element being bound. This isn't used.
* @param {String} event the event type (subscribe).
* @param {String} selector the subscription name
* @param {String} cb the callback function's name
*/
jQuery.Controller.processors.subscribe = function( el, event, selector, cb, controller ) {
var subscription = OpenAjax.hub.subscribe(selector, function(){
return controller[cb].apply(controller, arguments)
});
return function() {
OpenAjax.hub.unsubscribe(subscription);
};
};
/**
* @add jQuery.Controller.prototype
*/
//breaker
/**
* @function publish
* @hide
* Publishes a message to OpenAjax.hub.
* @param {String} message Message name, ex: "Something.Happened".
* @param {Object} data The data sent.
*/
jQuery.Controller.prototype.publish = function() {
OpenAjax.hub.publish.apply(OpenAjax.hub, arguments);
};
});