maintain context for contextual binding handlers - fixes #2146

pull/2231/head
Richard Harris 6 years ago
parent 07ceb2e767
commit 0fae80cf1d

@ -290,13 +290,8 @@ export default class ElementWrapper extends Wrapper {
});
}
const eventHandlerOrBindingUsesComponent = (
this.bindings.length > 0 ||
this.node.handlers.some(handler => handler.usesComponent)
);
const eventHandlerOrBindingUsesContext = (
this.bindings.some(binding => binding.node.usesContext) ||
this.bindings.some(binding => binding.handler.usesContext) ||
this.node.handlers.some(handler => handler.usesContext) ||
this.node.actions.some(action => action.usesContext)
);

@ -0,0 +1,50 @@
export default {
html: `
<div>
<input type="checkbox"><p>one</p>
</div>
<div>
<input type="checkbox"><p>two</p>
</div>
<div>
<input type="checkbox"><p>three</p>
</div>
`,
ssrHtml: `
<div>
<input type="checkbox"><p>one</p>
</div>
<div>
<input type="checkbox"><p>two</p>
</div>
<div>
<input type="checkbox"><p>three</p>
</div>
`,
async test({ assert, component, target, window }) {
const inputs = [ ...target.querySelectorAll('input') ];
const event = new window.Event('change');
inputs[1].checked = true;
await inputs[1].dispatchEvent(event);
await component.clear();
assert.htmlEqual(target.innerHTML, `
<div><input type="checkbox"><p>one</p></div>
<div><input type="checkbox"><p>three</p></div>
`);
inputs[1].checked = true;
await inputs[1].dispatchEvent(event);
await component.clear();
assert.htmlEqual(target.innerHTML, `
<div><input type="checkbox"><p>one</p></div>
`);
}
};

@ -0,0 +1,18 @@
<script>
let todos = [
{ done: false, text: 'one' },
{ done: false, text: 'two' },
{ done: false, text: 'three' }
];
export function clear() {
todos = todos.filter(t => !t.done);
}
</script>
{#each todos as todo, i}
<div>
<input type=checkbox bind:checked={todo.done}>
<p>{todo.text}</p>
</div>
{/each}
Loading…
Cancel
Save