Skip to content

Commit

Permalink
fix: include model reference in declaratively bound events (#3078) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vaadin-bot authored Nov 18, 2021
1 parent cfb4c69 commit d231f6e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export class Templatizer extends PolymerElement {
}, {});

this.__TemplateClass = templatize(this.__template, this, {
// Events handled by declarative event listeners
// (`on-event="handler"`) will be decorated with a `model` property pointing
// to the template instance that stamped it.
parentModel: true,
// This property prevents the template instance properties
// from passing into the `forwardHostProp` callback
instanceProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@ describe('vaadin-template-renderer', () => {
expect(spy.calledOnce).to.be.true;
});

it('should include model in the event', () => {
const host = fixtureSync(`<mock-component-host></mock-component-host>`);
const component = host.$.component;
const button = component.$.content.querySelector('button');
const spy = sinon.spy(host, 'onClick');

click(button);

expect(spy.getCall(0).args[0].model).to.equal(component.$.content.__templateInstance);
});

it('should re-render the template instance when changing a parent property', async () => {
const host = fixtureSync(`<mock-component-host></mock-component-host>`);
const component = host.$.component;
Expand Down

0 comments on commit d231f6e

Please sign in to comment.