-
Notifications
You must be signed in to change notification settings - Fork 0
/
pubsub.js
37 lines (31 loc) · 1.03 KB
/
pubsub.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
var PubSubManager = function() {
var _instance = null;
function NotificationManager() {
var observerMap = {};
// subscribe for a specified notification.
this.subscribe = function(notification, observerProc) {
if (!(notification in observerMap)) {
observerMap[notification] = [];
}
observerMap[notification].push(observerProc);
};
// publish an notification.
this.publish = function(notification, params) {
if (notification in observerMap) {
var notifyList = observerMap[notification];
for (var index = 0; index < notifyList.length; ++index) {
notifyList[index](params);
}
}
};
}
return {
// method to get an instance of PubSubManager
getInstance : function() {
if(!_instance){
_instance = new NotificationManager();;
}
return _instance;
}
};
}();