Merge pull request #1220 from sveltejs/gh-1206

add each_value to contextProps
pull/1226/head
Rich Harris 7 years ago committed by GitHub
commit e34b913a19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -75,6 +75,7 @@ export default class EachBlock extends Node {
} }
this.contextProps = [ this.contextProps = [
`${this.block.listName}: ${this.block.listName}`,
`${this.context}: ${this.block.listName}[#i]`, `${this.context}: ${this.block.listName}[#i]`,
`${this.block.indexName}: #i` `${this.block.indexName}: #i`
]; ];

@ -212,6 +212,7 @@ function create_main_fragment(component, state) {
for (var i = 0; i < comments.length; i += 1) { for (var i = 0; i < comments.length; i += 1) {
each_blocks[i] = create_each_block(component, assign({}, state, { each_blocks[i] = create_each_block(component, assign({}, state, {
comments: comments,
comment: comments[i], comment: comments[i],
i: i i: i
})); }));
@ -244,6 +245,7 @@ function create_main_fragment(component, state) {
if (changed.comments || changed.elapsed || changed.time) { if (changed.comments || changed.elapsed || changed.time) {
for (var i = 0; i < comments.length; i += 1) { for (var i = 0; i < comments.length; i += 1) {
var each_context = assign({}, state, { var each_context = assign({}, state, {
comments: comments,
comment: comments[i], comment: comments[i],
i: i i: i
}); });

@ -10,6 +10,7 @@ function create_main_fragment(component, state) {
for (var i = 0; i < comments.length; i += 1) { for (var i = 0; i < comments.length; i += 1) {
each_blocks[i] = create_each_block(component, assign({}, state, { each_blocks[i] = create_each_block(component, assign({}, state, {
comments: comments,
comment: comments[i], comment: comments[i],
i: i i: i
})); }));
@ -42,6 +43,7 @@ function create_main_fragment(component, state) {
if (changed.comments || changed.elapsed || changed.time) { if (changed.comments || changed.elapsed || changed.time) {
for (var i = 0; i < comments.length; i += 1) { for (var i = 0; i < comments.length; i += 1) {
var each_context = assign({}, state, { var each_context = assign({}, state, {
comments: comments,
comment: comments[i], comment: comments[i],
i: i i: i
}); });

@ -0,0 +1,19 @@
export default {
html: `
<button>racoon</button>
<button>eagle</button>
`,
test(assert, component, target) {
assert.htmlEqual(target.innerHTML,`
<button>racoon</button>
<button>eagle</button>
`);
const button = target.querySelector('button');
const event = new window.MouseEvent('click');
button.dispatchEvent(event);
assert.equal(component.get('clicked'), 'racoon');
},
};

@ -0,0 +1,11 @@
{{#each ['racoon', 'eagle'] as animal}}
<button on:click="set({clicked: animal})">{{animal}}</button>
{{/each}}
<script>
export default {
data: () => ({
clicked: null,
}),
};
</script>
Loading…
Cancel
Save