Skip to content

add behaviors to instances too #4397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 9, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/legacy/class.html
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
behaviors = superBehaviors.concat(behaviors);
}
klass.behaviors = behaviors;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this off the class if we're putting it on the prototype.

klass.prototype.behaviors = behaviors;
Copy link
Member Author

@valdrinkoshi valdrinkoshi Mar 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this should belong to the mixin or the legacy element, same for properties.
Should I just have two getters for properties and behaviors in the LegacyElementMixin?

return klass;
}

Expand Down
10 changes: 10 additions & 0 deletions test/unit/mixin-behaviors.html
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@
assert.equal(el.__label, 'foo');
});

test('instance and class behaviors', function() {
assert.equal(el.constructor.behaviors.length, 1);
assert.deepEqual(el.behaviors, el.constructor.behaviors);
});

test('listener from behavior', function() {
el.fire('change', {value: 'bar'});
assert.equal(el.__change, 'bar');
Expand Down Expand Up @@ -447,6 +452,11 @@
assert.equal(el.__readyB, true);
});

test('instance and class behaviors', function() {
assert.equal(el.constructor.behaviors.length, 2);
assert.deepEqual(el.behaviors, el.constructor.behaviors);
});

test('properties from behaviors', function() {
el.label = 'foo';
assert.equal(el.__label, 'foo');
Expand Down