Skip to content

Commit 2bdd24b

Browse files
authored
fix: include model reference in declaratively bound events (#3078)
1 parent fd71343 commit 2bdd24b

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎packages/polymer-legacy-adapter/src/template-renderer-templatizer.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ export class Templatizer extends PolymerElement {
101101
}, {});
102102

103103
this.__TemplateClass = templatize(this.__template, this, {
104+
// Events handled by declarative event listeners
105+
// (`on-event="handler"`) will be decorated with a `model` property pointing
106+
// to the template instance that stamped it.
107+
parentModel: true,
104108
// This property prevents the template instance properties
105109
// from passing into the `forwardHostProp` callback
106110
instanceProps,

‎packages/polymer-legacy-adapter/test/vaadin-template-renderer.test.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,17 @@ describe('vaadin-template-renderer', () => {
119119
expect(spy.calledOnce).to.be.true;
120120
});
121121

122+
it('should include model in the event', () => {
123+
const host = fixtureSync(`<mock-component-host></mock-component-host>`);
124+
const component = host.$.component;
125+
const button = component.$.content.querySelector('button');
126+
const spy = sinon.spy(host, 'onClick');
127+
128+
click(button);
129+
130+
expect(spy.getCall(0).args[0].model).to.equal(component.$.content.__templateInstance);
131+
});
132+
122133
it('should re-render the template instance when changing a parent property', async () => {
123134
const host = fixtureSync(`<mock-component-host></mock-component-host>`);
124135
const component = host.$.component;

0 commit comments

Comments
 (0)