reduce indentation

pull/10798/head
Rich Harris 2 years ago
parent 8641aeb619
commit 98cffcf0b0

@ -358,174 +358,173 @@ function reconcile_tracked_array(array, each_block, dom, is_controlled, render_f
var a = a_blocks.length; var a = a_blocks.length;
var b = array.length; var b = array.length;
/** @type {Array<import('#client').EachItemBlock>} */ // fast path  array is empty
var b_blocks;
var block;
if (b === 0) { if (b === 0) {
// Remove old blocks // Remove old blocks
if (is_controlled && a !== 0) { if (is_controlled && a !== 0) {
clear_text_content(dom); clear_text_content(dom);
} }
while (a > 0) { while (a > 0) {
block = a_blocks[--a]; destroy_each_item_block(a_blocks[--a], is_controlled);
destroy_each_item_block(block, is_controlled);
} }
b_blocks = []; each_block.v = [];
} else { return;
var a_end = a - 1; }
var b_end = b - 1;
var key;
var item;
var i;
b_blocks = Array(b);
if (a === 0) {
// Create new blocks
while (b > 0) {
i = b_end - --b;
block = each_item_block(array[i], keys[i], i, render_fn, flags);
b_blocks[i] = block;
insert_each_item_block(block, dom, is_controlled, null);
}
} else {
var is_animated = (flags & EACH_IS_ANIMATED) !== 0;
var should_update_block =
(flags & (EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE)) !== 0 || is_animated;
var start = 0;
/** @type {null | Text | Element | Comment} */ /** @type {Array<import('#client').EachItemBlock>} */
var sibling = null; var b_blocks = Array(b);
item = array[b_end];
key = keys[b_end]; // fast path — array WAS empty
if (a === 0) {
// Create new blocks
for (var i = 0; i < b; i += 1) {
var block = each_item_block(array[i], keys[i], i, render_fn, flags);
b_blocks[i] = block;
insert_each_item_block(block, dom, is_controlled, null);
}
// Step 1 each_block.v = b_blocks;
outer: while (true) { return;
// From the end }
while (a_blocks[a_end].k === key) {
block = a_blocks[a_end--];
item = array[b_end];
if (should_update_block) { var a_end = a - 1;
update_each_item_block(block, item, b_end, flags); var b_end = b - 1;
} var key;
var item;
var is_animated = (flags & EACH_IS_ANIMATED) !== 0;
var should_update_block =
is_animated || (flags & (EACH_ITEM_REACTIVE | EACH_INDEX_REACTIVE)) !== 0;
var start = 0;
/** @type {null | Text | Element | Comment} */
var sibling = null;
item = array[b_end];
key = keys[b_end];
// Step 1
outer: while (true) {
// From the end
while (a_blocks[a_end].k === key) {
block = a_blocks[a_end--];
item = array[b_end];
sibling = get_first_child(block); if (should_update_block) {
b_blocks[b_end] = block; update_each_item_block(block, item, b_end, flags);
}
if (start > --b_end || start > a_end) { sibling = get_first_child(block);
break outer; b_blocks[b_end] = block;
}
key = keys[b_end]; if (start > --b_end || start > a_end) {
} break outer;
}
item = array[start]; key = keys[b_end];
key = keys[start]; }
// At the start item = array[start];
while (start <= a_end && start <= b_end && a_blocks[start].k === key) { key = keys[start];
item = array[start];
block = a_blocks[start];
if (should_update_block) {
update_each_item_block(block, item, start, flags);
}
b_blocks[start] = block;
++start;
key = keys[start];
}
break; // At the start
while (start <= a_end && start <= b_end && a_blocks[start].k === key) {
item = array[start];
block = a_blocks[start];
if (should_update_block) {
update_each_item_block(block, item, start, flags);
} }
b_blocks[start] = block;
++start;
key = keys[start];
}
// Step 2 break;
if (start > a_end) { }
while (b_end >= start) {
block = each_item_block(array[b_end], keys[b_end], b_end, render_fn, flags);
b_blocks[b_end--] = block;
sibling = insert_each_item_block(block, dom, is_controlled, sibling);
}
} else if (start > b_end) {
b = start;
do { // Step 2
if ((block = a_blocks[b++]) !== null) { if (start > a_end) {
destroy_each_item_block(block); while (b_end >= start) {
} block = each_item_block(array[b_end], keys[b_end], b_end, render_fn, flags);
} while (b <= a_end); b_blocks[b_end--] = block;
} else { sibling = insert_each_item_block(block, dom, is_controlled, sibling);
// Step 3 }
var pos = 0; } else if (start > b_end) {
var b_length = b_end - start + 1; b = start;
var sources = new Int32Array(b_length);
var item_index = new Map();
for (b = 0; b < b_length; ++b) {
a = b + start;
sources[b] = NEW_BLOCK;
item = array[a];
map_set(item_index, keys[a], a);
}
// If keys are animated, we need to do updates before actual moves do {
if (is_animated) { if ((block = a_blocks[b++]) !== null) {
for (b = start; b <= a_end; ++b) { destroy_each_item_block(block);
a = map_get(item_index, /** @type {V} */ (a_blocks[b].k)); }
if (a !== undefined) { } while (b <= a_end);
item = array[a]; } else {
block = a_blocks[b]; // Step 3
update_each_item_block(block, item, a, flags); var pos = 0;
} var b_length = b_end - start + 1;
} var sources = new Int32Array(b_length);
} var item_index = new Map();
for (b = 0; b < b_length; ++b) {
a = b + start;
sources[b] = NEW_BLOCK;
item = array[a];
map_set(item_index, keys[a], a);
}
for (b = start; b <= a_end; ++b) { // If keys are animated, we need to do updates before actual moves
a = map_get(item_index, /** @type {V} */ (a_blocks[b].k)); if (is_animated) {
for (b = start; b <= a_end; ++b) {
a = map_get(item_index, /** @type {V} */ (a_blocks[b].k));
if (a !== undefined) {
item = array[a];
block = a_blocks[b]; block = a_blocks[b];
if (a !== undefined) { update_each_item_block(block, item, a, flags);
pos = pos < a ? a : MOVED_BLOCK;
sources[a - start] = b;
b_blocks[a] = block;
} else if (block !== null) {
destroy_each_item_block(block);
}
} }
}
}
// Step 4 for (b = start; b <= a_end; ++b) {
if (pos === MOVED_BLOCK) { a = map_get(item_index, /** @type {V} */ (a_blocks[b].k));
mark_lis(sources); block = a_blocks[b];
} if (a !== undefined) {
pos = pos < a ? a : MOVED_BLOCK;
sources[a - start] = b;
b_blocks[a] = block;
} else if (block !== null) {
destroy_each_item_block(block);
}
}
var last_block; // Step 4
var last_sibling; if (pos === MOVED_BLOCK) {
var should_create; mark_lis(sources);
}
while (b_length-- > 0) { var last_block;
b_end = b_length + start; var last_sibling;
a = sources[b_length]; var should_create;
should_create = a === -1;
item = array[b_end];
if (should_create) { while (b_length-- > 0) {
block = each_item_block(item, keys[b_end], b_end, render_fn, flags); b_end = b_length + start;
} else { a = sources[b_length];
block = b_blocks[b_end]; should_create = a === -1;
if (!is_animated && should_update_block) { item = array[b_end];
update_each_item_block(block, item, b_end, flags);
}
}
if (should_create || (pos === MOVED_BLOCK && a !== LIS_BLOCK)) {
last_sibling = last_block === undefined ? sibling : get_first_child(last_block);
sibling = insert_each_item_block(block, dom, is_controlled, last_sibling);
}
b_blocks[b_end] = block; if (should_create) {
last_block = block; block = each_item_block(item, keys[b_end], b_end, render_fn, flags);
} else {
block = b_blocks[b_end];
if (!is_animated && should_update_block) {
update_each_item_block(block, item, b_end, flags);
} }
} }
if (should_create || (pos === MOVED_BLOCK && a !== LIS_BLOCK)) {
last_sibling = last_block === undefined ? sibling : get_first_child(last_block);
sibling = insert_each_item_block(block, dom, is_controlled, last_sibling);
}
b_blocks[b_end] = block;
last_block = block;
} }
} }

Loading…
Cancel
Save