-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventBus.js
44 lines (41 loc) · 1.12 KB
/
EventBus.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
/**
* A MooTools implementation of an event bus to decouple
* the event sender from the receiver. It is very similar to
* NSNotificationCenter in Cocoa.
*
* MooTools Class.Extras already implements events. This class
* acts as a tiny wrapper around the Class event system of MooTools
*
* @author Anurag Mishra
* @date 2010/03/03
*
*/
var EventBus = new Class({
Implements: Events,
/**
* Register observer for the given notification.
*
* @param notification:string Name of the notification
* @param observer:Object The observing object
*/
addObserver: function(notification, observer) {
this.addEvent(notification, observer);
},
/**
* Remove observer for the given notification.
*
* @param notification:string Name of the notification
* @param observer:Object The observing object
*/
removeObserver: function(notification, observer) {
this.removeEvent(notification, observer);
},
/**
* Broadcast notification to all registered observers
*
* @param notification:string Name of the notification
*/
postNotification: function(notification, data) {
this.fireEvent(notification, data);
}
});