Skip to content

Commit 352bb3d

Browse files
committed
ensure hoisted event handler names are globally unique — fixes #466
1 parent c61ce13 commit 352bb3d

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

src/generators/dom/visitors/Element/EventHandler.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function visitEventHandler ( generator, block, state, node, attri
4444
// get a name for the event handler that is globally unique
4545
// if hoisted, locally unique otherwise
4646
const handlerName = shouldHoist ?
47-
generator.alias( `${name}_handler` ) :
47+
generator.getUniqueName( `${name}_handler` ) :
4848
block.getUniqueName( `${name}_handler` );
4949

5050
// create the handler body
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
export default {
2+
data: {
3+
foo: [ 1 ],
4+
bar: [ 2 ],
5+
clicked: 'neither'
6+
},
7+
8+
html: `
9+
<button>foo</button>
10+
<button>bar</button>
11+
<p>clicked: neither</p>
12+
`,
13+
14+
test ( assert, component, target, window ) {
15+
const buttons = target.querySelectorAll( 'button' );
16+
const event = new window.MouseEvent( 'click' );
17+
18+
buttons[0].dispatchEvent( event );
19+
assert.equal( component.get( 'clicked' ), 'foo' );
20+
assert.htmlEqual( target.innerHTML, `
21+
<button>foo</button>
22+
<button>bar</button>
23+
<p>clicked: foo</p>
24+
` );
25+
26+
buttons[1].dispatchEvent( event );
27+
assert.equal( component.get( 'clicked' ), 'bar' );
28+
assert.htmlEqual( target.innerHTML, `
29+
<button>foo</button>
30+
<button>bar</button>
31+
<p>clicked: bar</p>
32+
` );
33+
34+
component.destroy();
35+
}
36+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{#each foo as f}}
2+
<button on:click='set({ clicked: "foo" })'>foo</button>
3+
{{/each}}
4+
5+
{{#each bar as b}}
6+
<button on:click='set({ clicked: "bar" })'>bar</button>
7+
{{/each}}
8+
9+
<p>clicked: {{clicked}}</p>

0 commit comments

Comments
 (0)