extend dependency tracking to all directives

pull/1797/head
Rich Harris 6 years ago
parent 3258779fa7
commit 073c8762ef

@ -163,13 +163,16 @@ export default class ElementWrapper extends Wrapper {
block.addAnimation();
}
if (node.classes) {
node.classes.forEach(({ expression }) => {
if (expression) {
block.addDependencies(expression.dependencies);
// add directive and handler dependencies
[node.animation, node.outro, ...node.actions, ...node.classes].forEach(directive => {
if (directive && directive.expression) {
block.addDependencies(directive.expression.dependencies);
}
});
}
node.handlers.forEach(handler => {
block.addDependencies(handler.dependencies);
});
if (this.parent) {
if (node.actions.length > 0) this.parent.cannotUseInnerHTML();

@ -0,0 +1,21 @@
export default {
data: {
items: [
'whatever'
],
foo: 'wrong',
bar: 'right'
},
test(assert, component, target, window) {
const button = target.querySelector('button');
const event = new window.MouseEvent('click');
button.dispatchEvent(event);
assert.equal(component.get().foo, 'right');
component.set({ bar: 'left' });
button.dispatchEvent(event);
assert.equal(component.get().foo, 'left');
}
};

@ -0,0 +1,5 @@
{#each items as item}
<button on:click='set({ foo: bar })'>{item}</button>
{/each}
<p>foo: {foo}</p>
Loading…
Cancel
Save