From 0190e330e8e743ae829b3ac99168147e98ee0217 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Wed, 31 Oct 2018 18:03:19 -0700 Subject: [PATCH] Address review feedback * Uses `window.ShadyCSS.cssBuild` to avoid doing unnecessary work in `processElementStyles` * Stores the list of active in-use behaviors in a legacy element's `behaviors` property. This only matters in the exotic case when elements with behaviors are extended with more behaviors and previously the list included only the subclasses behaviors (although the element otherwise worked as expected). --- lib/legacy/class.html | 22 +++++++++++----------- lib/mixins/element-mixin.html | 4 +++- test/unit/mixin-behaviors.html | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/legacy/class.html b/lib/legacy/class.html index 671b297dd3..930015b757 100644 --- a/lib/legacy/class.html +++ b/lib/legacy/class.html @@ -203,9 +203,9 @@ static get properties() { const properties = {}; - if (this.prototype.behaviors) { - for (let i=0, b; i < this.prototype.behaviors.length; i++) { - b = this.prototype.behaviors[i]; + if (this.prototype.__behaviors) { + for (let i=0, b; i < this.prototype.__behaviors.length; i++) { + b = this.prototype.__behaviors[i]; mergeProperties(properties, b.properties); } } @@ -215,9 +215,9 @@ static get observers() { let observers = []; - if (this.prototype.behaviors) { - for (let i=0, b; i < this.prototype.behaviors.length; i++) { - b = this.prototype.behaviors[i]; + if (this.prototype.__behaviors) { + for (let i=0, b; i < this.prototype.__behaviors.length; i++) { + b = this.prototype.__behaviors[i]; if (b.observers) { observers = observers.concat(b.observers); } @@ -273,8 +273,8 @@ `is` in `beforeRegister` as you could in 1.x. */ const proto = this; - if (proto.hasOwnProperty('behaviors')) { - copyBehaviorProperties(proto.behaviors, proto.constructor); + if (proto.hasOwnProperty('__behaviors')) { + copyBehaviorProperties(proto.__behaviors, proto.constructor); } proto.__behaviorMetaProps = proto.__behaviorMetaProps || {}; copyProperties(info, proto); @@ -420,12 +420,12 @@ if (!Array.isArray(behaviors)) { behaviors = [behaviors]; } - let superBehaviors = PolymerGenerated.prototype.__allBehaviors; + let superBehaviors = PolymerGenerated.prototype.behaviors; // get flattened, deduped list of behaviors *not* already on super class behaviors = flattenBehaviors(behaviors, null, superBehaviors); - PolymerGenerated.prototype.__allBehaviors = superBehaviors ? + PolymerGenerated.prototype.behaviors = superBehaviors ? superBehaviors.concat(behaviors) : behaviors; - PolymerGenerated.prototype.behaviors = behaviors; + PolymerGenerated.prototype.__behaviors = behaviors; } PolymerGenerated.generatedFrom = info; diff --git a/lib/mixins/element-mixin.html b/lib/mixins/element-mixin.html index 3a0f3b7fad..dce111c712 100644 --- a/lib/mixins/element-mixin.html +++ b/lib/mixins/element-mixin.html @@ -21,6 +21,8 @@ (function() { 'use strict'; + const builtCSS = window.ShadyCSS && window.ShadyCSS['cssBuild']; + /** * Element class mixin that provides the core API for Polymer's meta-programming * features including template stamping, data-binding, attribute deserialization, @@ -252,7 +254,7 @@ * @private */ function processElementStyles(klass, template, is, baseURI) { - if (!window.skipStyleIncludesAndUrls) { + if (!builtCSS) { const templateStyles = template.content.querySelectorAll('style'); const stylesWithImports = Polymer.StyleGather.stylesFromTemplate(template); // insert styles from at the top of the template diff --git a/test/unit/mixin-behaviors.html b/test/unit/mixin-behaviors.html index 730f7ceb2b..6f4dc50428 100644 --- a/test/unit/mixin-behaviors.html +++ b/test/unit/mixin-behaviors.html @@ -551,7 +551,7 @@ }); test('nested-behavior dedups', function() { - assert.equal(el.behaviors.length, 2); + assert.equal(el.behaviors.length, 6); }); test('nested-behavior lifecycle', function() {