lazyCopyProps

This commit is contained in:
Kevin Schaaf
2018-10-26 18:06:53 -07:00
parent 2f78573357
commit a7847816ef
+21 -17
View File
@@ -63,7 +63,6 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
return GenerateClassFromInfo({}, klass);
}
function applyBehaviors(behaviors, klass) {
if (!behaviors) {
klass = /** @type {HTMLElement} */(klass); // eslint-disable-line no-self-assign
@@ -72,7 +71,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// 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];
}
@@ -80,7 +79,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// 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);
}
@@ -120,14 +119,16 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
// (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;
}
/**
@@ -286,22 +287,25 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
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);
}
}
@@ -428,7 +432,7 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
PolymerGenerated.generatedFrom = info;
copyProperties(info, PolymerGenerated.prototype);
// copyProperties(info, PolymerGenerated.prototype);
return PolymerGenerated;
}