Skip to content

Commit

Permalink
extend dependency tracking to all directives
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Oct 24, 2018
1 parent 3258779 commit 073c876
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/compile/render-dom/wrappers/Element/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
21 changes: 21 additions & 0 deletions test/runtime/samples/event-handler-each-context/_config.js
Original file line number Diff line number Diff line change
@@ -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');
}
};
5 changes: 5 additions & 0 deletions test/runtime/samples/event-handler-each-context/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{#each items as item}
<button on:click='set({ foo: bar })'>{item}</button>
{/each}

<p>foo: {foo}</p>

0 comments on commit 073c876

Please sign in to comment.