Skip to content

Commit

Permalink
invoke registration behavior before registering features, so behavi…
Browse files Browse the repository at this point in the history
…ors can alter features, this requires calling behavior flattening as part of prototype desugaring instead of as part of behavior prep, so the flattened list is available early
  • Loading branch information
Scott J Miles committed Aug 25, 2015
1 parent 61d611c commit 6224dc3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/lib/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

// `this` context is a prototype, not an instance
registerCallback: function() {
// TODO(sjmiles): perhaps this method should be called from polymer-bootstrap?
this._desugarBehaviors(); // abstract
this._doBehavior('registered'); // abstract
this._registerFeatures(); // abstract
},
Expand Down
19 changes: 15 additions & 4 deletions src/lib/polymer-bootstrap.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,23 @@
var userPolymer = window.Polymer;

window.Polymer = function(prototype) {
var ctor = desugar(prototype);
// Polymer.Base is now chained to ctor.prototype, and for IE10 compat
// if input is a `class` (aka a function with a prototype), use the prototype
// remember that the `constructor` will never be called
if (typeof prototype === 'function') {
prototype = prototype.prototype;
}
// if there is no prototype, use a default empty object
if (!prototype) {
prototype = {};
}
// desugar the prototype and return a factory object
var factory = desugar(prototype);
// Polymer.Base is now chained to factory.prototype, and for IE10 compat
// this may have resulted in a new prototype being created
prototype = ctor.prototype;
prototype = factory.prototype;
// native Custom Elements treats 'undefined' extends property
// as valued, the property must not exist to be ignored
// TODO(sjmiles): Custom Elements no longer has the above behavior
var options = {
prototype: prototype
};
Expand All @@ -34,7 +45,7 @@
}
Polymer.telemetry._registrate(prototype);
document.registerElement(prototype.is, options);
return ctor;
return factory;
};

var desugar = function(prototype) {
Expand Down
9 changes: 6 additions & 3 deletions src/micro/behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@
*/
behaviors: [],

_prepBehaviors: function() {
_desugarBehaviors: function() {
if (this.behaviors.length) {
this.behaviors = this._flattenBehaviorsList(this.behaviors);
}
this._prepAllBehaviors(this.behaviors);
},

_flattenBehaviorsList: function(behaviors) {
Expand All @@ -81,7 +80,11 @@
return flat;
},

_prepAllBehaviors: function(behaviors) {
_prepBehaviors: function() {
this._prepFlattenedBehaviors(this.behaviors);
},

_prepFlattenedBehaviors: function(behaviors) {
// traverse the behaviors in _reverse_ order (youngest first) because
// `_mixinBehavior` has _first property wins_ behavior, this is done
// to optimize # of calls to `_copyOwnProperty`
Expand Down

0 comments on commit 6224dc3

Please sign in to comment.