forked from thinkpixellab/pl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
behavior.js
36 lines (28 loc) · 869 Bytes
/
behavior.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
goog.provide('pl.Behavior');
goog.require('goog.array');
goog.require('goog.asserts');
goog.require('pl.Property');
/**
* @constructor
* @param {!Object} element
*/
pl.Behavior = function(element) {
this._element = element;
var behaviors = pl.Behavior._behaviorsProperty.get(element);
if (!behaviors) {
behaviors = [];
pl.Behavior._behaviorsProperty.set(element, behaviors);
}
behaviors.push(this);
};
pl.Behavior.prototype.detach = function() {
goog.asserts.assert(this._element);
var behaviors = pl.Behavior._behaviorsProperty.get(this._element);
goog.asserts.assert(goog.array.contains(behaviors, this));
goog.array.remove(behaviors, this);
if (behaviors.length === 0) {
pl.Behavior._behaviorsProperty.clear(this._element);
}
this._element = undefined;
};
pl.Behavior._behaviorsProperty = new pl.Property('Behaviors');