forked from tedsuo/ref-binder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathref_binder.js
37 lines (30 loc) · 865 Bytes
/
ref_binder.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
// If this file is modified copy it to es_client/vendor/
if (typeof define !== 'function') { var define = require('amdefine')(module) }
define( function(require){
var RefBinder = function(target){
this._ref = {};
this.target = target;
}
RefBinder.prototype.get = function(name,obj,events){
return this._ref[name];
};
RefBinder.prototype.set = function(name,obj,events){
this.unset(name);
if(!obj) return;
for(var e_name in events){
obj.on( e_name, this.target[events[e_name]], this.target);
}
this._ref[name] = obj;
};
RefBinder.prototype.unset = function(name){
if(!this._ref[name]) return;
this._ref[name].off(null,null,this);
delete this._ref[name];
};
RefBinder.prototype.unsetAll = function(){
for(var name in this._ref){
this.unset(name);
}
};
return RefBinder;
});