Skip to content

Commit bb38dff

Browse files
committed
observe properties via compound path observer.
1 parent 74086fb commit bb38dff

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

src/instance/properties.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
var properties = {
2121
// set up property observers
22+
/*
2223
observeProperties: function() {
2324
// TODO(sjmiles):
2425
// we observe published properties so we can reflect them to attributes
@@ -48,6 +49,7 @@
4849
}
4950
}
5051
},
52+
*/
5153
_observe: function(name, cb) {
5254
log.observe && console.log(LOG_OBSERVE, this.localName, name);
5355
registerObserver(this, name,
@@ -81,7 +83,49 @@
8183
},
8284
unbindAllProperties: function() {
8385
unregisterObservers(this);
84-
}
86+
if (this._propertyObserver) {
87+
this._propertyObserver.close();
88+
}
89+
},
90+
91+
observeProperties: function() {
92+
var n$ = this._observeNames, pn$ = this._publishNames;
93+
if ((n$ && n$.length) || (pn$ && pn$.length)) {
94+
var self = this;
95+
var o = this._propertyObserver = new CompoundPathObserver(function(
96+
newValues, oldValues, changedBits) {
97+
self.notifyPropertyChanges(newValues, oldValues, changedBits);
98+
}, this, undefined, undefined);
99+
var p = this._propertyObserverNames = [];
100+
for (var i=0, l=n$.length, n; (i<l) && (n=n$[i]); i++) {
101+
p.push(n);
102+
o.addPath(this, n);
103+
}
104+
for (var i=0, l=pn$.length, n; (i<l) && (n=pn$[i]); i++) {
105+
if (!this.observe || (this.observe[n] === undefined)) {
106+
p.push(n);
107+
o.addPath(this, n);
108+
}
109+
}
110+
//console.log(p);
111+
o.start();
112+
}
113+
},
114+
115+
notifyPropertyChanges: function(newValues, oldValues, changedBits) {
116+
for (var i=0, l=changedBits.length, n; i<l; i++) {
117+
if (changedBits[i]) {
118+
n = this._propertyObserverNames[i];
119+
//console.log(n, this.publish[n], this.observe[n]);
120+
if (this.publish[n] !== undefined) {
121+
this.relectPropertyToAttribute(n);
122+
}
123+
if (this.observe[n]) {
124+
invoke.call(this, this.observe[n], [oldValues[i]]);
125+
}
126+
}
127+
}
128+
},
85129
};
86130

87131
function invoke(method, args) {
@@ -135,10 +179,16 @@
135179
}
136180

137181
function getElementObservers(element) {
182+
//window.timer && timer.time('getElementObservers');
183+
var b$ = element._propertyBindingObservers ||
184+
(element._propertyBindingObservers = {});
185+
/*
138186
var b$ = observers.get(element);
139187
if (!b$) {
140188
observers.set(element, b$ = {});
141189
}
190+
*/
191+
//window.timer && timer.timeEnd('getElementObservers');
142192
return b$;
143193
}
144194

0 commit comments

Comments
 (0)