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

alias #component in hoisted event handlers #701

Merged
merged 1 commit into from
Jul 8, 2017
Merged
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.ts
Original file line number Diff line number Diff line change
@@ -45,7 +45,7 @@ export default function visitEventHandler(
const declarations = usedContexts.map(name => {
if (name === 'state') {
if (shouldHoist) state.usesComponent = true;
return `var state = #component.get();`;
return `var state = ${block.alias('component')}.get();`;
}

const listName = block.listNames.get(name);
18 changes: 18 additions & 0 deletions test/runtime/samples/event-handler-hoisted/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default {
data: {
foo: [1],
a: 42
},

html: `
<button>click me</button>
`,

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

button.dispatchEvent(event);
assert.equal(component.snapshot, 42);
}
};
13 changes: 13 additions & 0 deletions test/runtime/samples/event-handler-hoisted/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{#each foo as bar}}
<button on:click='baz(a)'>click me</button>
{{/each}}

<script>
export default {
methods: {
baz(a) {
this.snapshot = a;
}
}
};
</script>