Skip to content

Commit

Permalink
make event handler names unique across components - fixes #1919
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Harris authored and Richard Harris committed Dec 29, 2018
1 parent ff2a21e commit fc0b49e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compile/render-dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ export default class ElementWrapper extends Wrapper {
.filter(group => group.bindings.length);

groups.forEach(group => {
const handler = block.getUniqueName(`${this.var}_${group.events.join('_')}_handler`);
const handler = renderer.component.getUniqueName(`${this.var}_${group.events.join('_')}_handler`);
renderer.component.declarations.push(handler);
renderer.component.template_references.add(handler);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export default {
props: {
foo: 'a',
items: ['x'],
},

html: `
<div><input><p>a</p></div>
<div><input><p>x</p></div>
`,

ssrHtml: `
<div><input value=a><p>a</p></div>
<div><input value=x><p>x</p></div>
`,

async test({ assert, component, target, window }) {
const inputs = [...target.querySelectorAll('input')];
const items = component.items;
const event = new window.Event('input');

assert.equal(inputs[0].value, 'a');

inputs[0].value = 'b';
inputs[1].value = 'y';
await inputs[0].dispatchEvent(event);
await inputs[1].dispatchEvent(event);

assert.equal(component.foo, 'b');
assert.equal(component.items[0], 'y');

assert.htmlEqual(target.innerHTML, `
<div><input><p>b</p></div>
<div><input><p>y</p></div>
`);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div><input bind:value={foo}><p>{foo}</p></div>

{#each items as bar}
<div><input bind:value={bar}><p>{bar}</p></div>
{/each}

0 comments on commit fc0b49e

Please sign in to comment.