Skip to content
This repository was archived by the owner on Mar 13, 2018. It is now read-only.

Commit 8807978

Browse files
committed
Element creation steps refined for performance: bindings are now applied before shadowRoot is created.
1 parent 327aa5b commit 8807978

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/instance/base.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,31 @@
3131
}
3232
this.created();
3333
this.prepareElement();
34+
if (!this.ownerDocument.isStagingDocument) {
35+
this.makeElementReady();
36+
}
3437
},
3538
// system entry point, do not override
3639
prepareElement: function() {
40+
if (this._elementPrepared) {
41+
console.warn('Element already prepared', this.localName);
42+
return;
43+
}
3744
this._elementPrepared = true;
38-
// install shadowRoots storage
45+
// storage for shadowRoots info
3946
this.shadowRoots = {};
40-
// storage for closeable observers.
41-
this._observers = [];
4247
// install property observers
43-
this.observeProperties();
48+
this.createPropertyObserver();
4449
// install boilerplate attributes
4550
this.copyInstanceAttributes();
4651
// process input attributes
4752
this.takeAttributes();
4853
// add event listeners
4954
this.addHostListeners();
55+
},
56+
makeElementReady: function() {
57+
// TODO(sorvell): We could create an entry point here
58+
// for the user to compute property values.
5059
// process declarative resources
5160
this.parseDeclarations(this.__proto__);
5261
// TODO(sorvell): CE polyfill uses unresolved attribute to simulate
@@ -55,6 +64,8 @@
5564
this.removeAttribute('unresolved');
5665
// user entry point
5766
this.ready();
67+
// turn on property observation and take any initial changes
68+
this.openPropertyObserver();
5869
},
5970
attachedCallback: function() {
6071
this.cancelUnbindAll();

src/instance/mdv.js

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
return observer;
4040
}
4141
},
42+
bindFinished: function() {
43+
this.makeElementReady();
44+
},
4245
// TODO(sorvell): unbind/unbindAll has been removed, as public api, from
4346
// TemplateBinding. We still need to close/dispose of observers but perhaps
4447
// we should choose a more explicit name.

src/instance/properties.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
var empty = [];
1919

2020
var properties = {
21-
observeProperties: function() {
21+
createPropertyObserver: function() {
2222
var n$ = this._observeNames, pn$ = this._publishNames;
2323
if ((n$ && n$.length) || (pn$ && pn$.length)) {
2424
var self = this;
25-
var o = this._propertyObserver = new CompoundObserver();
25+
var o = this._propertyObserver = new CompoundObserver(true);
2626
// keep track of property observer so we can shut it down
2727
this.registerObservers([o]);
2828
for (var i=0, l=n$.length, n; (i<l) && (n=n$[i]); i++) {
@@ -38,7 +38,11 @@
3838
o.addPath(this, n);
3939
}
4040
}
41-
o.open(this.notifyPropertyChanges, this);
41+
}
42+
},
43+
openPropertyObserver: function() {
44+
if (this._propertyObserver) {
45+
this._propertyObserver.open(this.notifyPropertyChanges, this);
4246
}
4347
},
4448
notifyPropertyChanges: function(newValues, oldValues, paths) {
@@ -90,6 +94,7 @@
9094
}
9195
},
9296
registerObservers: function(observers) {
97+
this._observers = this._observers || [];
9398
this._observers.push(observers);
9499
},
95100
// observer array items are arrays of observers.

0 commit comments

Comments
 (0)