Skip to content

Commit

Permalink
Merge pull request #1427 from sveltejs/dynamic-component-shorthand-event
Browse files Browse the repository at this point in the history
fix handling of shorthand event handler in dynamic components
  • Loading branch information
Rich-Harris authored May 6, 2018
2 parents c7c46de + b45b264 commit 53816ee
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compile/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export default class Component extends Node {
${this.handlers.map(handler => deindent`
function ${handler.var}(event) {
${handler.snippet}
${handler.snippet || `#component.fire("${handler.name}", event);`}
}
if (${name}) ${name}.on("${handler.name}", ${handler.var});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button on:click='fire("foo", { answer: 42 })'>click me</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
html: `
<button>click me</button>
`,

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

let answer;
component.on('foo', event => {
answer = event.answer;
});

button.dispatchEvent(event);
assert.equal(answer, 42);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<svelte:component this={Widget} on:foo/>

<script>
import Widget from './Widget.html';

export default {
data: () => ({ Widget })
};
</script>

0 comments on commit 53816ee

Please sign in to comment.