-
Notifications
You must be signed in to change notification settings - Fork 11
/
module.js
27 lines (26 loc) · 860 Bytes
/
module.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
Module = Class.extend((function(){
var _init = function(sandbox, options){
if (!sandbox || !(sandbox instanceof Sandbox)) throw new TypeError("Sandbox");
this.sandbox = sandbox;
},
_initSubscribedMessagesCallbacks = function(sandbox, subscribesTo){
if (typeof subscribesTo === "undefined") return;
for (var callback in subscribesTo){
if (subscribesTo.hasOwnProperty(callback)) {
if (typeof subscribesTo[callback] !== "function"){
throw new TypeError(callback + "is not a function");
}
sandbox.subscribe(callback, subscribesTo[callback]);
}
}
};
return {
initialize: function(sandbox, options){
if (typeof this.init === "function") {
this.init(sandbox, options);
}
_init(sandbox, options);
_initSubscribedMessagesCallbacks(sandbox, this.subscribesTo || {});
}
}
})());