Skip to content
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

ensure hoisted event handler names are globally unique #467

Merged
merged 2 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/generators/dom/visitors/Element/EventHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export default function visitEventHandler ( generator, block, state, node, attri
// get a name for the event handler that is globally unique
// if hoisted, locally unique otherwise
const handlerName = shouldHoist ?
generator.alias( `${name}_handler` ) :
generator.getUniqueName( `${name}_handler` ) :
block.getUniqueName( `${name}_handler` );

// create the handler body
Expand Down
36 changes: 36 additions & 0 deletions test/runtime/samples/event-handler-each-deconflicted/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export default {
data: {
foo: [ 1 ],
bar: [ 2 ],
clicked: 'neither'
},

html: `
<button>foo</button>
<button>bar</button>
<p>clicked: neither</p>
`,

test ( assert, component, target, window ) {
const buttons = target.querySelectorAll( 'button' );
const event = new window.MouseEvent( 'click' );

buttons[0].dispatchEvent( event );
assert.equal( component.get( 'clicked' ), 'foo' );
assert.htmlEqual( target.innerHTML, `
<button>foo</button>
<button>bar</button>
<p>clicked: foo</p>
` );

buttons[1].dispatchEvent( event );
assert.equal( component.get( 'clicked' ), 'bar' );
assert.htmlEqual( target.innerHTML, `
<button>foo</button>
<button>bar</button>
<p>clicked: bar</p>
` );

component.destroy();
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{{#each foo as f}}
<button on:click='set({ clicked: "foo" })'>foo</button>
{{/each}}

{{#each bar as b}}
<button on:click='set({ clicked: "bar" })'>bar</button>
{{/each}}

<p>clicked: {{clicked}}</p>