Skip to content

Commit 7822ed2

Browse files
committed
Merge branch 'master' into 2.x-disable-upgrade
2 parents 50ae3bb + a158a1f commit 7822ed2

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/legacy/class.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@
5454
if (!Array.isArray(behaviors)) {
5555
behaviors = [behaviors];
5656
}
57-
let superBehaviors = klass.behaviors;
57+
let superBehaviors = klass.prototype.behaviors;
5858
// get flattened, deduped list of behaviors *not* already on super class
5959
behaviors = flattenBehaviors(behaviors, null, superBehaviors);
6060
// mixin new behaviors
6161
klass = _mixinBehaviors(behaviors, klass);
6262
if (superBehaviors) {
6363
behaviors = superBehaviors.concat(behaviors);
6464
}
65-
klass.behaviors = behaviors;
65+
// Set behaviors on prototype for BC...
66+
klass.prototype.behaviors = behaviors;
6667
return klass;
6768
}
6869

@@ -320,8 +321,6 @@
320321
LegacyElementMixin(HTMLElement));
321322
// decorate klass with registration info
322323
klass.is = info.is;
323-
// behaviors on prototype for BC...
324-
klass.prototype.behaviors = klass.behaviors;
325324
// NOTE: while we could call `beforeRegister` here to maintain
326325
// some BC, the state of the element at this point is not as it was in 1.0
327326
// In 1.0, the method was called *after* mixing prototypes together

test/unit/mixin-behaviors.html

+13-5
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
this._createMethodObserver('propChanged2(prop)');
285285
this.registeredCount++;
286286
this.registeredProps = [this.prop1, this.prop2, this.prop3];
287-
this.registeredBehaviors = this.constructor.behaviors;
287+
this.registeredBehaviors = this.behaviors;
288288
},
289289
prop1: true,
290290
ready: function() {
@@ -382,6 +382,10 @@
382382
assert.equal(el.__label, 'foo');
383383
});
384384

385+
test('instance behaviors', function() {
386+
assert.equal(el.behaviors.length, 1);
387+
});
388+
385389
test('listener from behavior', function() {
386390
el.fire('change', {value: 'bar'});
387391
assert.equal(el.__change, 'bar');
@@ -413,7 +417,7 @@
413417
var el = fixture('registered');
414418
assert.equal(el.registeredCount, 4);
415419
assert.equal(el.registeredBehaviors.length, 3);
416-
assert.equal(el.registeredBehaviors, el.constructor.behaviors);
420+
assert.equal(el.registeredBehaviors, el.behaviors);
417421
assert.deepEqual(el.registeredProps, [true, true, true]);
418422
});
419423

@@ -447,6 +451,10 @@
447451
assert.equal(el.__readyB, true);
448452
});
449453

454+
test('instance behaviors', function() {
455+
assert.equal(el.behaviors.length, 2);
456+
});
457+
450458
test('properties from behaviors', function() {
451459
el.label = 'foo';
452460
assert.equal(el.__label, 'foo');
@@ -510,13 +518,13 @@
510518
test('behavior array is unique', function() {
511519
customElements.define('behavior-unique', Polymer.mixinBehaviors(
512520
[Polymer.BehaviorA, Polymer.BehaviorA], Polymer.Element));
513-
assert.equal(document.createElement('behavior-unique').constructor.behaviors.length, 1);
521+
assert.equal(document.createElement('behavior-unique').behaviors.length, 1);
514522
});
515523

516524
test('duplicate behaviors keep first behavior', function() {
517525
customElements.define('behavior-unique-last-behavior', Polymer.mixinBehaviors(
518526
[Polymer.BehaviorA, Polymer.BehaviorB, Polymer.BehaviorC, Polymer.BehaviorA, Polymer.BehaviorB], Polymer.Element));
519-
var behaviors = document.createElement('behavior-unique-last-behavior').constructor.behaviors;
527+
var behaviors = document.createElement('behavior-unique-last-behavior').behaviors;
520528
assert.deepEqual(behaviors, [Polymer.BehaviorC, Polymer.BehaviorA, Polymer.BehaviorB]);
521529
});
522530

@@ -530,7 +538,7 @@
530538
});
531539

532540
test('nested-behavior dedups', function() {
533-
assert.equal(el.constructor.behaviors.length, 4);
541+
assert.equal(el.behaviors.length, 4);
534542
});
535543

536544
test('nested-behavior overrides ordering', function() {

0 commit comments

Comments
 (0)