Skip to content

Commit

Permalink
Merge pull request #1220 from sveltejs/gh-1206
Browse files Browse the repository at this point in the history
add each_value to contextProps
  • Loading branch information
Rich-Harris authored Mar 9, 2018
2 parents 89c830e + d680356 commit e34b913
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/generators/nodes/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export default class EachBlock extends Node {
}

this.contextProps = [
`${this.block.listName}: ${this.block.listName}`,
`${this.context}: ${this.block.listName}[#i]`,
`${this.block.indexName}: #i`
];
Expand Down
2 changes: 2 additions & 0 deletions test/js/samples/each-block-changed-check/expected-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ function create_main_fragment(component, state) {

for (var i = 0; i < comments.length; i += 1) {
each_blocks[i] = create_each_block(component, assign({}, state, {
comments: comments,
comment: comments[i],
i: i
}));
Expand Down Expand Up @@ -244,6 +245,7 @@ function create_main_fragment(component, state) {
if (changed.comments || changed.elapsed || changed.time) {
for (var i = 0; i < comments.length; i += 1) {
var each_context = assign({}, state, {
comments: comments,
comment: comments[i],
i: i
});
Expand Down
2 changes: 2 additions & 0 deletions test/js/samples/each-block-changed-check/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function create_main_fragment(component, state) {

for (var i = 0; i < comments.length; i += 1) {
each_blocks[i] = create_each_block(component, assign({}, state, {
comments: comments,
comment: comments[i],
i: i
}));
Expand Down Expand Up @@ -42,6 +43,7 @@ function create_main_fragment(component, state) {
if (changed.comments || changed.elapsed || changed.time) {
for (var i = 0; i < comments.length; i += 1) {
var each_context = assign({}, state, {
comments: comments,
comment: comments[i],
i: i
});
Expand Down
19 changes: 19 additions & 0 deletions test/runtime/samples/each-block-array-literal/_config.js
Original file line number Diff line number Diff line change
@@ -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');
},
};
11 changes: 11 additions & 0 deletions test/runtime/samples/each-block-array-literal/main.html
Original file line number Diff line number Diff line change
@@ -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>

0 comments on commit e34b913

Please sign in to comment.