Skip to content

Commit

Permalink
fix spread when an attribute or prop has multiple dependencies (#1515)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conduitry committed May 30, 2018
1 parent 7032ec7 commit 755f085
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compile/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export default class Component extends Node {
const { name, dependencies } = attr;

const condition = dependencies.size > 0 && (dependencies.size !== allDependencies.size)
? [...dependencies].map(d => `changed.${d}`).join(' || ')
? `(${[...dependencies].map(d => `changed.${d}`).join(' || ')})`
: null;

if (attr.isSpread) {
Expand Down
2 changes: 1 addition & 1 deletion src/compile/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ export default class Element extends Node {
.filter(attr => attr.type === 'Attribute' || attr.type === 'Spread')
.forEach(attr => {
const condition = attr.dependencies.size > 0
? [...attr.dependencies].map(d => `changed.${d}`).join(' || ')
? `(${[...attr.dependencies].map(d => `changed.${d}`).join(' || ')})`
: null;

if (attr.isSpread) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{foo} {baz}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
html: `b baz`,
test(assert, component, target) {
component.set({ foo: true });
assert.htmlEqual(
target.innerHTML,
`a baz`
);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Widget foo={foo ? a : b} {...bar}/>

<script>
export default {
components: { Widget: './Widget.html' },
data: () => ({
foo: false,
a: 'a',
b: 'b',
bar: { baz: 'baz' },
}),
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default {
html: `<div class='b' title='baz'></div>`,
test(assert, component, target) {
component.set({ foo: true });
assert.htmlEqual(
target.innerHTML,
`<div class='a' title='baz'></div>`
);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class={foo ? a : b} {...bar}></div>

<script>
export default {
data: () => ({
foo: false,
a: 'a',
b: 'b',
bar: { title: 'baz' },
}),
};
</script>

0 comments on commit 755f085

Please sign in to comment.