Skip to content

Commit a784781

Browse files
committed
lazyCopyProps
1 parent 2f78573 commit a784781

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

lib/legacy/class.html

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
return GenerateClassFromInfo({}, klass);
6464
}
6565

66-
6766
function applyBehaviors(behaviors, klass) {
6867
if (!behaviors) {
6968
klass = /** @type {HTMLElement} */(klass); // eslint-disable-line no-self-assign
@@ -72,15 +71,15 @@
7271
// NOTE: ensure the behavior is extending a class with
7372
// legacy element api. This is necessary since behaviors expect to be able
7473
// to access 1.x legacy api.
75-
klass = class extends Polymer.LegacyElementMixin(klass) {};
74+
klass = class extends Polymer.LegacyElementMixin(klass) { };
7675
if (!Array.isArray(behaviors)) {
7776
behaviors = [behaviors];
7877
}
7978
let superBehaviors = klass.prototype.behaviors;
8079
// get flattened, deduped list of behaviors *not* already on super class
8180
behaviors = flattenBehaviors(behaviors, null, superBehaviors);
8281
// mixin new behaviors
83-
klass = _applyBehaviors(behaviors, klass);
82+
// klass = _applyBehaviors(behaviors, klass);
8483
if (superBehaviors) {
8584
behaviors = superBehaviors.concat(behaviors);
8685
}
@@ -120,14 +119,16 @@
120119
// (1) C.created, (2) A.created, (3) B.created, (4) element.created
121120
// (again same as 1.x)
122121
function _applyBehaviors(behaviors, klass) {
123-
for (let i=0; i<behaviors.length; i++) {
124-
let b = behaviors[i];
125-
if (b) {
126-
Array.isArray(b) ? _applyBehaviors(b, klass) :
127-
copyProperties(b, klass.prototype);
122+
if (behaviors) {
123+
for (let i=0; i<behaviors.length; i++) {
124+
let b = behaviors[i];
125+
// if (b) {
126+
// Array.isArray(b) ? _applyBehaviors(b, klass) :
127+
copyProperties(b, klass.prototype);
128+
// }
128129
}
130+
return klass;
129131
}
130-
return klass;
131132
}
132133

133134
/**
@@ -286,22 +287,25 @@
286287
in `beforeRegister` or `registered`. It is no longer possible to set
287288
`is` in `beforeRegister` as you could in 1.x.
288289
*/
289-
if (this.behaviors) {
290-
for (let i=0, b; i < this.behaviors.length; i++) {
291-
b = this.behaviors[i];
290+
const proto = Object.getPrototypeOf(this);
291+
_applyBehaviors(proto.behaviors, proto.constructor);
292+
copyProperties(info, proto);
293+
if (proto.behaviors) {
294+
for (let i=0, b; i < proto.behaviors.length; i++) {
295+
b = proto.behaviors[i];
292296
if (b.beforeRegister) {
293-
b.beforeRegister.call(Object.getPrototypeOf(this));
297+
b.beforeRegister.call(proto);
294298
}
295299
if (b.registered) {
296-
b.registered.call(Object.getPrototypeOf(this));
300+
b.registered.call(proto);
297301
}
298302
}
299303
}
300304
if (info.beforeRegister) {
301-
info.beforeRegister.call(Object.getPrototypeOf(this));
305+
info.beforeRegister.call(proto);
302306
}
303307
if (info.registered) {
304-
info.registered.call(Object.getPrototypeOf(this));
308+
info.registered.call(proto);
305309
}
306310
}
307311

@@ -428,7 +432,7 @@
428432

429433
PolymerGenerated.generatedFrom = info;
430434

431-
copyProperties(info, PolymerGenerated.prototype);
435+
// copyProperties(info, PolymerGenerated.prototype);
432436

433437
return PolymerGenerated;
434438
}

0 commit comments

Comments
 (0)