diff --git a/lib/legacy/class.html b/lib/legacy/class.html
index 68e84755d6..671b297dd3 100644
--- a/lib/legacy/class.html
+++ b/lib/legacy/class.html
@@ -62,34 +62,7 @@
* @suppress {invalidCasts, checkTypes}
*/
function mixinBehaviors(behaviors, klass) {
- if (behaviors) {
- klass = applyBehaviors(behaviors, klass);
- }
- // provides behaviors functionality
- return GenerateClassFromInfo({}, klass);
- }
-
- function applyBehaviors(behaviors, klass) {
- if (!behaviors) {
- klass = /** @type {HTMLElement} */(klass); // eslint-disable-line no-self-assign
- return klass;
- }
- // 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) { };
- 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);
- if (superBehaviors) {
- behaviors = superBehaviors.concat(behaviors);
- }
- // Set behaviors on prototype
- klass.prototype.behaviors = behaviors;
- return klass;
+ return GenerateClassFromInfo({}, Polymer.LegacyElementMixin(klass), behaviors);
}
// NOTE:
@@ -124,20 +97,21 @@
// (again same as 1.x)
function copyBehaviorProperties(behaviors, klass) {
const meta = {};
+ const superMeta = klass.prototype.__behaviorMetaProps;
if (behaviors) {
klass.prototype.__behaviorMetaProps = meta;
for (let i=0; i
HTMLImports.whenReady(function() {
customElements.define('nested-behaviors',
- class extends Polymer.mixinBehaviors(
+ class extends Polymer.mixinBehaviors([window.BehaviorD, window.LifeCycleBehavior1], Polymer.mixinBehaviors(
[
- [window.BehaviorB, [window.BehaviorC, window.BehaviorB], window.BehaviorA],
- [window.BehaviorD]
- ], Polymer.Element) {
+ [window.BehaviorB, [window.BehaviorC, window.BehaviorB], window.BehaviorA, window.LifeCycleBehavior2],
+ ], Polymer.Element)) {
});
});
@@ -356,7 +355,7 @@
-
+
@@ -552,7 +551,13 @@
});
test('nested-behavior dedups', function() {
- assert.equal(el.behaviors.length, 4);
+ assert.equal(el.behaviors.length, 2);
+ });
+
+ test('nested-behavior lifecycle', function() {
+ assert.equal(el._calledCreated, 2, 'created call count wrong');
+ assert.equal(el._calledAttached, 2, 'attached call count wrong');
+ assert.equal(el._calledAttributeChanged, 1, 'attributeChanged call count wrong');
});
test('nested-behavior overrides ordering', function() {