Skip to content

Commit

Permalink
avoid configuration work when unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Nov 3, 2015
1 parent 66df196 commit e0fbfbe
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 48 deletions.
2 changes: 0 additions & 2 deletions polymer-micro.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
_registerFeatures: function() {
// identity
this._prepIs();
// attributes
this._prepAttributes();
// shared behaviors
this._prepBehaviors();
// factory
Expand Down
21 changes: 11 additions & 10 deletions polymer-mini.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
_registerFeatures: function() {
// identity
this._prepIs();
// attributes
this._prepAttributes();
// shared behaviors
this._prepBehaviors();
// factory
Expand All @@ -43,14 +41,17 @@
},

_initFeatures: function() {
// manage local dom
this._poolContent();
// host stack
this._pushHost();
// instantiate template
this._stampTemplate();
// host stack
this._popHost();
this._calcHost();
if (this._template) {
// manage local dom
this._poolContent();
// host stack
this._beginHost();
// instantiate template
this._stampTemplate();
// host stack
this._popHost();
}
// install host attributes
this._marshalHostAttributes();
// setup debouncers
Expand Down
33 changes: 18 additions & 15 deletions polymer.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
_registerFeatures: function() {
// identity
this._prepIs();
// attributes
this._prepAttributes();
// factory
this._prepConstructor();
// template
Expand Down Expand Up @@ -59,37 +57,42 @@
},

_initFeatures: function() {
// manage local dom
this._poolContent();
// manage configuration
this._setupConfigure();
// setup style properties
this._setupStyleProperties();
// host stack
this._pushHost();
// instantiate template
this._stampTemplate();
// host stack
this._popHost();
// concretize template references
this._marshalAnnotationReferences();
// setup debouncers
this._setupDebouncers();
this._calcHost();
if (this._template) {
// manage local dom
this._poolContent();
// host stack
this._beginHost();
// instantiate template
this._stampTemplate();
// host stack
this._popHost();
// concretize template references
this._marshalAnnotationReferences();
}
// concretize effects on instance
this._marshalInstanceEffects();
// acquire instance behaviors
this._marshalBehaviors();
// install host attributes
this._marshalHostAttributes();
// acquire initial instance attribute values
this._marshalAttributes();
// install host attributes
this._marshalHostAttributes();
// top-down initial distribution, configuration, & ready callback
this._tryReady();
},

_marshalBehavior: function(b) {
// establish listeners on instance
this._listenListeners(b.listeners);
if (b.listeners) {
this._listenListeners(b.listeners);
}
}

});
Expand Down
8 changes: 5 additions & 3 deletions src/lib/template/templatizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,15 @@
// Similar to Polymer.Base.extend, but retains any previously set instance
// values (_propertySetter back on instance once accessor is installed)
_extendTemplate: function(template, proto) {
Object.getOwnPropertyNames(proto).forEach(function(n) {
var n$ = Object.getOwnPropertyNames(proto);
for (var i=0, n; (i<n$.length) && (n=n$[i]); i++) {
var val = template[n];
var pd = Object.getOwnPropertyDescriptor(proto, n);
Object.defineProperty(template, n, pd);
if (val !== undefined) {
template._propertySetter(n, val);
}
});
}
},

// Extension points for Templatizer sub-classes
Expand Down Expand Up @@ -331,7 +332,8 @@
_constructorImpl: function(model, host) {
this._rootDataHost = host._getRootDataHost();
this._setupConfigure(model);
this._pushHost(host);
this._calcHost(host);
this._beginHost();
this.root = this.instanceTemplate(this._template);
this.root.__noContent = !this._notes._hasContent;
this.root.__styleScoped = true;
Expand Down
37 changes: 20 additions & 17 deletions src/mini/ready.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,23 @@
// In order not to over-emphaisize this technical difference, we expose
// one concept to the user and it maps to the dom-related meaning of host.
//
// 1. set this element's `host` and push this element onto the `host`'s
// set this element's `host` and push this element onto the `host`'s
// list of `client` elements
// 2. establish this element as the current hosting element (allows
// any elements we stamp to easily set host to us).
_pushHost: function(host) {
// this.dataHost reflects the parent element who manages
// any bindings for the element. Only elements originally
// stamped from Polymer templates have a dataHost, and this
// never changes
_calcHost: function(host) {
// NOTE: The `dataHost` of an element never changes.
this.dataHost = host = host ||
this.dataHost = host = host ||
Polymer.Base._hostStack[Polymer.Base._hostStack.length-1];
// this.dataHost reflects the parent element who manages
// any bindings for the element. Only elements originally
// stamped from Polymer templates have a dataHost, and this
// never changes
if (host && host._clients) {
host._clients.push(this);
}
this._beginHost();
},

// establish this element as the current hosting element (allows
// any elements we stamp to easily set host to us).
_beginHost: function() {
Polymer.Base._hostStack.push(this);
if (!this._clients) {
Expand All @@ -99,9 +98,13 @@
_ready: function() {
// extension point
this._beforeClientsReady();
// prepare root
this._setupRoot();
this._readyClients();
if (this._template) {
// prepare root
this._setupRoot();
this._readyClients();
}
this._clientsReadied = true;
this._clients = null;
// extension point
this._afterClientsReady();
this._readySelf();
Expand All @@ -112,8 +115,10 @@
this._beginDistribute();
// now fully prepare localChildren
var c$ = this._clients;
for (var i=0, l= c$.length, c; (i<l) && (c=c$[i]); i++) {
c._ready();
if (c$) {
for (var i=0, l= c$.length, c; (i<l) && (c=c$[i]); i++) {
c._ready();
}
}
// perform actual dom composition
this._finishDistribute();
Expand All @@ -123,8 +128,6 @@
// if (!Polymer.Settings.useNativeCustomElements) {
// CustomElements.takeRecords();
// }
this._clientsReadied = true;
this._clients = null;
},

// mark readied and call `ready`
Expand Down
4 changes: 3 additions & 1 deletion src/standard/configure.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@
// this is the new _config, which are the final values to be applied
this._config = config;
// pass configuration data to bindings
this._distributeConfig(this._config);
if (this._clients && this._clients.length) {
this._distributeConfig(this._config);
}
},

_configureProperties: function(properties, config) {
Expand Down

0 comments on commit e0fbfbe

Please sign in to comment.