Skip to content

Add array destructuring for each contexts#889

Merged
Rich-Harris merged 3 commits intosveltejs:masterfrom
jacobmischka:destructure-each
Oct 17, 2017
Merged

Add array destructuring for each contexts#889
Rich-Harris merged 3 commits intosveltejs:masterfrom
jacobmischka:destructure-each

Conversation

@jacobmischka
Copy link
Copy Markdown
Contributor

@jacobmischka jacobmischka commented Oct 10, 2017

Example repo, ran with svelte npm linked to branch as indicated in readme.

Note this does not do object destructuring, just array destructuring.

Input:

<div>
	{{#each Object.entries(map) as [key, value], i}}
		<h2>{{ key }}: {{ i }}</h2>
		{{#each Object.entries(value) as [subkey, subvalue], j}}
			<p>
				{{subkey}}: {{subvalue}}
			</p>
		{{/each}}
	{{/each}}
</div>

<script>
export default {
	data() {
		return {
			map: {
				key: {
					subkey: 'subval',
					subkey2: 'subval2'
				},
				anotherKey: {
					anotherSubkey: 'anotherSubval',
					anotherSubkey2: 'anotherSubval2'
				}
			}
		};
	}
};
</script>

Result:
screenshot from 2017-10-09 20-37-46

Fixes #888

@jacobmischka
Copy link
Copy Markdown
Contributor Author

Oops hang on I forgot some tests and missed some ssr bugs, will reopen when fixed

@jacobmischka jacobmischka reopened this Oct 10, 2017
@jacobmischka
Copy link
Copy Markdown
Contributor Author

Okay looks like CI doesn't like Object.entries in the test, fair enough.

@Rich-Harris Rich-Harris merged commit c394aa7 into sveltejs:master Oct 17, 2017
@Rich-Harris
Copy link
Copy Markdown
Member

Nice, thank you!

sacrosanctic pushed a commit to sacrosanctic/svelte that referenced this pull request Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants