Skip to content
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

use anchor comments to preserve order in keyed each blocks with components #704

Merged
merged 1 commit into from
Jul 10, 2017
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/dom/visitors/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ function keyed(
block.addVariable(head);
block.addVariable(last);

if (node.children[0] && node.children[0].type === 'Element') {
if (node.children[0] && node.children[0].type === 'Element' && !generator.components.has(node.children[0].name)) {
// TODO or text/tag/raw
node._block.first = node.children[0]._state.parentNode; // TODO this is highly confusing
} else {
Expand Down
1 change: 1 addition & 0 deletions test/runtime/samples/each-block-keyed-unshift/Nested.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>{{title}}</p>
24 changes: 24 additions & 0 deletions test/runtime/samples/each-block-keyed-unshift/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export default {
data: {
titles: [{ name: 'b' }, { name: 'c' }]
},

html: `
<p>b</p>
<p>c</p>
`,

test (assert, component, target) {
component.set({
titles: [{ name: 'a' }, { name: 'b' }, { name: 'c' }]
});

assert.htmlEqual(target.innerHTML, `
<p>a</p>
<p>b</p>
<p>c</p>
`);

component.destroy();
}
};
13 changes: 13 additions & 0 deletions test/runtime/samples/each-block-keyed-unshift/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{#each titles as title @name}}
<Nested title="{{title.name}}"/>
{{/each}}

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

export default {
components: {
Nested
}
};
</script>