fix indentation

pull/5835/head
Conduitry 5 years ago
parent 1f4c90615e
commit 2987260e98

@ -259,18 +259,18 @@ function get_binding_group(renderer: Renderer, value: Binding, block: Block) {
const contexts = []; const contexts = [];
const contextual_dependencies = new Set<string>(); const contextual_dependencies = new Set<string>();
const { template_scope } = value.expression; const { template_scope } = value.expression;
const add_contextual_dependency = (dep: string) => { const add_contextual_dependency = (dep: string) => {
contextual_dependencies.add(dep); contextual_dependencies.add(dep);
const owner = template_scope.get_owner(dep); const owner = template_scope.get_owner(dep);
if (owner.type === 'EachBlock') { if (owner.type === 'EachBlock') {
for (const dep of owner.expression.contextual_dependencies) { for (const dep of owner.expression.contextual_dependencies) {
add_contextual_dependency(dep); add_contextual_dependency(dep);
} }
} }
}; };
for (const dep of value.expression.contextual_dependencies) { for (const dep of value.expression.contextual_dependencies) {
add_contextual_dependency(dep); add_contextual_dependency(dep);
} }
for (const dep of contextual_dependencies) { for (const dep of contextual_dependencies) {

@ -4,31 +4,31 @@ import ElementWrapper from '../Element';
import Binding from '../../../nodes/Binding'; import Binding from '../../../nodes/Binding';
export default function mark_each_block_bindings( export default function mark_each_block_bindings(
parent: ElementWrapper | InlineComponentWrapper, parent: ElementWrapper | InlineComponentWrapper,
binding: Binding binding: Binding
) { ) {
// we need to ensure that the each block creates a context including // we need to ensure that the each block creates a context including
// the list and the index, if they're not otherwise referenced // the list and the index, if they're not otherwise referenced
binding.expression.references.forEach(name => { binding.expression.references.forEach(name => {
const each_block = parent.node.scope.get_owner(name); const each_block = parent.node.scope.get_owner(name);
if (each_block) { if (each_block) {
(each_block as EachBlock).has_binding = true; (each_block as EachBlock).has_binding = true;
} }
}); });
if (binding.name === 'group') { if (binding.name === 'group') {
const add_index_binding = (name: string) => { const add_index_binding = (name: string) => {
const each_block = parent.node.scope.get_owner(name); const each_block = parent.node.scope.get_owner(name);
if (each_block.type === 'EachBlock') { if (each_block.type === 'EachBlock') {
each_block.has_index_binding = true; each_block.has_index_binding = true;
for (const dep of each_block.expression.contextual_dependencies) { for (const dep of each_block.expression.contextual_dependencies) {
add_index_binding(dep); add_index_binding(dep);
} }
} }
}; };
// for `<input bind:group={} >`, we make sure that all the each blocks creates context with `index` // for `<input bind:group={} >`, we make sure that all the each blocks creates context with `index`
for (const name of binding.expression.contextual_dependencies) { for (const name of binding.expression.contextual_dependencies) {
add_index_binding(name); add_index_binding(name);
} }
} }
} }

@ -1,5 +1,5 @@
export default { export default {
html: ` html: `
<input type="checkbox" value="a" data-index="x-1"> <input type="checkbox" value="a" data-index="x-1">
<input type="checkbox" value="b" data-index="x-1"> <input type="checkbox" value="b" data-index="x-1">
<input type="checkbox" value="c" data-index="x-1"> <input type="checkbox" value="c" data-index="x-1">
@ -20,8 +20,8 @@ export default {
<input type="checkbox" value="c" data-index="z-2"> <input type="checkbox" value="c" data-index="z-2">
`, `,
async test({ assert, component, target, window }) { async test({ assert, component, target, window }) {
const inputs = target.querySelectorAll('input'); const inputs = target.querySelectorAll('input');
const checked = new Set(); const checked = new Set();
const checkInbox = async (i) => { const checkInbox = async (i) => {
checked.add(i); checked.add(i);
@ -29,25 +29,25 @@ export default {
await inputs[i].dispatchEvent(event); await inputs[i].dispatchEvent(event);
}; };
for (let i = 0; i < 18; i++) { for (let i = 0; i < 18; i++) {
assert.equal(inputs[i].checked, checked.has(i)); assert.equal(inputs[i].checked, checked.has(i));
} }
const event = new window.Event('change'); const event = new window.Event('change');
await checkInbox(2); await checkInbox(2);
for (let i = 0; i < 18; i++) { for (let i = 0; i < 18; i++) {
assert.equal(inputs[i].checked, checked.has(i)); assert.equal(inputs[i].checked, checked.has(i));
} }
await checkInbox(12); await checkInbox(12);
for (let i = 0; i < 18; i++) { for (let i = 0; i < 18; i++) {
assert.equal(inputs[i].checked, checked.has(i)); assert.equal(inputs[i].checked, checked.has(i));
} }
await checkInbox(8); await checkInbox(8);
for (let i = 0; i < 18; i++) { for (let i = 0; i < 18; i++) {
assert.equal(inputs[i].checked, checked.has(i)); assert.equal(inputs[i].checked, checked.has(i));
} }
} }
}; };

@ -1,15 +1,15 @@
<script> <script>
const list = [ const list = [
{ id: 'x', data: [{ id: 1, data: [] }, { id: 2, data: [] }] }, { id: 'x', data: [{ id: 1, data: [] }, { id: 2, data: [] }] },
{ id: 'y', data: [{ id: 1, data: [] }, { id: 2, data: [] }] }, { id: 'y', data: [{ id: 1, data: [] }, { id: 2, data: [] }] },
{ id: 'z', data: [{ id: 1, data: [] }, { id: 2, data: [] }] } { id: 'z', data: [{ id: 1, data: [] }, { id: 2, data: [] }] }
]; ];
</script> </script>
{#each list as { id, data }} {#each list as { id, data }}
{#each data as item} {#each data as item}
<input type="checkbox" bind:group={item.data} value="a" data-index="{id}-{item.id}" /> <input type="checkbox" bind:group={item.data} value="a" data-index="{id}-{item.id}" />
<input type="checkbox" bind:group={item.data} value="b" data-index="{id}-{item.id}" /> <input type="checkbox" bind:group={item.data} value="b" data-index="{id}-{item.id}" />
<input type="checkbox" bind:group={item.data} value="c" data-index="{id}-{item.id}" /> <input type="checkbox" bind:group={item.data} value="c" data-index="{id}-{item.id}" />
{/each} {/each}
{/each} {/each}

Loading…
Cancel
Save