Skip to content

Commit

Permalink
lazyCopyProps
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed Oct 27, 2018
1 parent 2f78573 commit a784781
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions lib/legacy/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
return GenerateClassFromInfo({}, klass);
}


function applyBehaviors(behaviors, klass) {
if (!behaviors) {
klass = /** @type {HTMLElement} */(klass); // eslint-disable-line no-self-assign
Expand All @@ -72,15 +71,15 @@
// NOTE: ensure the behavior is extending a class with
// legacy element api. This is necessary since behaviors expect to be able
// to access 1.x legacy api.
klass = class extends Polymer.LegacyElementMixin(klass) {};
klass = class extends Polymer.LegacyElementMixin(klass) { };
if (!Array.isArray(behaviors)) {
behaviors = [behaviors];
}
let superBehaviors = klass.prototype.behaviors;
// get flattened, deduped list of behaviors *not* already on super class
behaviors = flattenBehaviors(behaviors, null, superBehaviors);
// mixin new behaviors
klass = _applyBehaviors(behaviors, klass);
// klass = _applyBehaviors(behaviors, klass);
if (superBehaviors) {
behaviors = superBehaviors.concat(behaviors);
}
Expand Down Expand Up @@ -120,14 +119,16 @@
// (1) C.created, (2) A.created, (3) B.created, (4) element.created
// (again same as 1.x)
function _applyBehaviors(behaviors, klass) {
for (let i=0; i<behaviors.length; i++) {
let b = behaviors[i];
if (b) {
Array.isArray(b) ? _applyBehaviors(b, klass) :
copyProperties(b, klass.prototype);
if (behaviors) {
for (let i=0; i<behaviors.length; i++) {
let b = behaviors[i];
// if (b) {
// Array.isArray(b) ? _applyBehaviors(b, klass) :
copyProperties(b, klass.prototype);
// }
}
return klass;
}
return klass;
}

/**
Expand Down Expand Up @@ -286,22 +287,25 @@
in `beforeRegister` or `registered`. It is no longer possible to set
`is` in `beforeRegister` as you could in 1.x.
*/
if (this.behaviors) {
for (let i=0, b; i < this.behaviors.length; i++) {
b = this.behaviors[i];
const proto = Object.getPrototypeOf(this);
_applyBehaviors(proto.behaviors, proto.constructor);
copyProperties(info, proto);
if (proto.behaviors) {
for (let i=0, b; i < proto.behaviors.length; i++) {
b = proto.behaviors[i];
if (b.beforeRegister) {
b.beforeRegister.call(Object.getPrototypeOf(this));
b.beforeRegister.call(proto);
}
if (b.registered) {
b.registered.call(Object.getPrototypeOf(this));
b.registered.call(proto);
}
}
}
if (info.beforeRegister) {
info.beforeRegister.call(Object.getPrototypeOf(this));
info.beforeRegister.call(proto);
}
if (info.registered) {
info.registered.call(Object.getPrototypeOf(this));
info.registered.call(proto);
}
}

Expand Down Expand Up @@ -428,7 +432,7 @@

PolymerGenerated.generatedFrom = info;

copyProperties(info, PolymerGenerated.prototype);
// copyProperties(info, PolymerGenerated.prototype);

return PolymerGenerated;
}
Expand Down

0 comments on commit a784781

Please sign in to comment.