Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
Steven Orvell committed Nov 1, 2018
1 parent efb8d71 commit 0190e33
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
22 changes: 11 additions & 11 deletions lib/legacy/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion lib/mixins/element-mixin.html
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 <link rel="import" type="css"> at the top of the template
Expand Down
2 changes: 1 addition & 1 deletion test/unit/mixin-behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 0190e33

Please sign in to comment.