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

Commit

Permalink
Element creation steps refined for performance: bindings are now appl…
Browse files Browse the repository at this point in the history
…ied before shadowRoot is created.
  • Loading branch information
sorvell committed Apr 17, 2014
1 parent 327aa5b commit 8807978
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
19 changes: 15 additions & 4 deletions src/instance/base.js
Expand Up @@ -31,22 +31,31 @@
}
this.created();
this.prepareElement();
if (!this.ownerDocument.isStagingDocument) {
this.makeElementReady();
}
},
// system entry point, do not override
prepareElement: function() {
if (this._elementPrepared) {
console.warn('Element already prepared', this.localName);
return;
}
this._elementPrepared = true;
// install shadowRoots storage
// storage for shadowRoots info
this.shadowRoots = {};
// storage for closeable observers.
this._observers = [];
// install property observers
this.observeProperties();
this.createPropertyObserver();
// install boilerplate attributes
this.copyInstanceAttributes();
// process input attributes
this.takeAttributes();
// add event listeners
this.addHostListeners();
},
makeElementReady: function() {
// TODO(sorvell): We could create an entry point here
// for the user to compute property values.
// process declarative resources
this.parseDeclarations(this.__proto__);
// TODO(sorvell): CE polyfill uses unresolved attribute to simulate
Expand All @@ -55,6 +64,8 @@
this.removeAttribute('unresolved');
// user entry point
this.ready();
// turn on property observation and take any initial changes
this.openPropertyObserver();
},
attachedCallback: function() {
this.cancelUnbindAll();
Expand Down
3 changes: 3 additions & 0 deletions src/instance/mdv.js
Expand Up @@ -39,6 +39,9 @@
return observer;
}
},
bindFinished: function() {
this.makeElementReady();
},
// TODO(sorvell): unbind/unbindAll has been removed, as public api, from
// TemplateBinding. We still need to close/dispose of observers but perhaps
// we should choose a more explicit name.
Expand Down
11 changes: 8 additions & 3 deletions src/instance/properties.js
Expand Up @@ -18,11 +18,11 @@
var empty = [];

var properties = {
observeProperties: function() {
createPropertyObserver: function() {
var n$ = this._observeNames, pn$ = this._publishNames;
if ((n$ && n$.length) || (pn$ && pn$.length)) {
var self = this;
var o = this._propertyObserver = new CompoundObserver();
var o = this._propertyObserver = new CompoundObserver(true);
// keep track of property observer so we can shut it down
this.registerObservers([o]);
for (var i=0, l=n$.length, n; (i<l) && (n=n$[i]); i++) {
Expand All @@ -38,7 +38,11 @@
o.addPath(this, n);
}
}
o.open(this.notifyPropertyChanges, this);
}
},
openPropertyObserver: function() {
if (this._propertyObserver) {
this._propertyObserver.open(this.notifyPropertyChanges, this);
}
},
notifyPropertyChanges: function(newValues, oldValues, paths) {
Expand Down Expand Up @@ -90,6 +94,7 @@
}
},
registerObservers: function(observers) {
this._observers = this._observers || [];
this._observers.push(observers);
},
// observer array items are arrays of observers.
Expand Down

0 comments on commit 8807978

Please sign in to comment.