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

add each_value to contextProps #1220

Merged
merged 4 commits into from
Mar 9, 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
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>