Skip to content

Update spread props in each blocks #1357

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

Merged
merged 2 commits into from
Apr 20, 2018
Merged
Show file tree
Hide file tree
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/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class Component extends Node {
attribute.expression.arguments.forEach((arg: Node) => {
block.addDependencies(arg.metadata.dependencies);
});
} else if (attribute.type === 'Binding') {
} else if (attribute.type === 'Binding' || attribute.type === 'Spread') {
block.addDependencies(attribute.metadata.dependencies);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/generators/nodes/Element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export default class Element extends Node {
}
} else if (attribute.type === 'Action' && attribute.expression) {
block.addDependencies(attribute.metadata.dependencies);
} else if (attribute.type === 'Spread') {
block.addDependencies(attribute.metadata.dependencies);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/utils/flattenReference.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Node } from '../interfaces';

export default function flatten(node: Node) {
export default function flattenReference(node: Node) {
const parts = [];
const propEnd = node.end;

Expand Down
1 change: 1 addition & 0 deletions test/runtime/samples/spread-each-component/Nested.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div data-a={a} data-b={b}></div>
26 changes: 26 additions & 0 deletions test/runtime/samples/spread-each-component/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
html: `
<div data-a="1" data-b="2"></div>
<div data-a="3" data-b="4"></div>
`,

data: {
things: [
{ a: 1, b: 2 },
{ a: 3, b: 4 }
]
},

test(assert, component, target) {
const { things } = component.get();

component.set({
things: things.reverse()
});

assert.htmlEqual(target.innerHTML, `
<div data-a="3" data-b="4"></div>
<div data-a="1" data-b="2"></div>
`);
},
};
11 changes: 11 additions & 0 deletions test/runtime/samples/spread-each-component/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{#each things as thing}
<Nested {...thing}/>
{/each}

<script>
import Nested from './Nested.html';

export default {
components: { Nested }
};
</script>
26 changes: 26 additions & 0 deletions test/runtime/samples/spread-each-element/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
html: `
<div data-a="1" data-b="2"></div>
<div data-c="3" data-d="4"></div>
`,

data: {
things: [
{ 'data-a': 1, 'data-b': 2 },
{ 'data-c': 3, 'data-d': 4 }
]
},

test(assert, component, target) {
const { things } = component.get();

component.set({
things: things.reverse()
});

assert.htmlEqual(target.innerHTML, `
<div data-c="3" data-d="4"></div>
<div data-a="1" data-b="2"></div>
`);
},
};
3 changes: 3 additions & 0 deletions test/runtime/samples/spread-each-element/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{#each things as thing}
<div {...thing}></div>
{/each}