|
|
@ -20,22 +20,36 @@ export function outroAndDestroyIteration(iteration, lookup) {
|
|
|
|
// TODO is it possible to avoid mounting iterations that are
|
|
|
|
// TODO is it possible to avoid mounting iterations that are
|
|
|
|
// already in the right place?
|
|
|
|
// already in the right place?
|
|
|
|
export function updateKeyedEach(component, key, changed, key_prop, dynamic, list, head, lookup, node, has_outro, create_each_block, intro_method, get_context) {
|
|
|
|
export function updateKeyedEach(component, key, changed, key_prop, dynamic, list, head, lookup, node, has_outro, create_each_block, intro_method, get_context) {
|
|
|
|
|
|
|
|
var expected = head;
|
|
|
|
|
|
|
|
|
|
|
|
var keep = {};
|
|
|
|
var keep = {};
|
|
|
|
|
|
|
|
var mounts = {};
|
|
|
|
|
|
|
|
|
|
|
|
var i = list.length;
|
|
|
|
for (var i = 0; i < list.length; i += 1) {
|
|
|
|
while (i--) {
|
|
|
|
|
|
|
|
var key = list[i][key_prop];
|
|
|
|
var key = list[i][key_prop];
|
|
|
|
var iteration = lookup[key];
|
|
|
|
var iteration = lookup[key];
|
|
|
|
|
|
|
|
var next_data = list[i+1];
|
|
|
|
|
|
|
|
var next = next_data && lookup[next_data[key_prop]];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (dynamic && iteration) iteration.p(changed, get_context(i)); // TODO should this be deferred? could it be redundant?
|
|
|
|
|
|
|
|
|
|
|
|
if (iteration) {
|
|
|
|
if (expected && (key === expected.key)) {
|
|
|
|
if (dynamic) iteration.p(changed, get_context(i));
|
|
|
|
var first = iteration && iteration.first;
|
|
|
|
|
|
|
|
var parentNode = first && first.parentNode
|
|
|
|
|
|
|
|
if (!parentNode || (iteration && iteration.next) != next) mounts[key] = iteration;
|
|
|
|
|
|
|
|
expected = iteration.next;
|
|
|
|
|
|
|
|
} else if (iteration) {
|
|
|
|
|
|
|
|
mounts[key] = iteration;
|
|
|
|
|
|
|
|
expected = iteration.next;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// key is being inserted
|
|
|
|
iteration = lookup[key] = create_each_block(component, key, get_context(i));
|
|
|
|
iteration = lookup[key] = create_each_block(component, key, get_context(i));
|
|
|
|
iteration.c();
|
|
|
|
iteration.c();
|
|
|
|
|
|
|
|
mounts[key] = iteration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lookup[key] = iteration;
|
|
|
|
lookup[key] = iteration;
|
|
|
|
keep[key] = 1;
|
|
|
|
keep[iteration.key] = iteration;
|
|
|
|
|
|
|
|
// last = iteration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var destroy = has_outro
|
|
|
|
var destroy = has_outro
|
|
|
@ -49,32 +63,35 @@ export function updateKeyedEach(component, key, changed, key_prop, dynamic, list
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var next = null;
|
|
|
|
var next = null;
|
|
|
|
|
|
|
|
var next_iteration = null;
|
|
|
|
|
|
|
|
|
|
|
|
i = list.length;
|
|
|
|
for (i = list.length - 1; i >= 0; i -= 1) {
|
|
|
|
while (i--) {
|
|
|
|
var data = list[i];
|
|
|
|
key = list[i][key_prop];
|
|
|
|
var key = data[key_prop];
|
|
|
|
iteration = lookup[key];
|
|
|
|
iteration = lookup[key];
|
|
|
|
|
|
|
|
|
|
|
|
var anchor;
|
|
|
|
var block = mounts[key];
|
|
|
|
|
|
|
|
if (block) {
|
|
|
|
if (has_outro) {
|
|
|
|
var anchor;
|
|
|
|
var next_key = next && next.key;
|
|
|
|
|
|
|
|
var neighbour = iteration.next;
|
|
|
|
|
|
|
|
var anchor_key;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (neighbour && anchor_key != next_key && !keep[anchor_key]) {
|
|
|
|
if (has_outro) {
|
|
|
|
anchor = neighbour && neighbour.first;
|
|
|
|
var key_next_iteration = next_iteration && next_iteration.key;
|
|
|
|
neighbour = neighbour.next;
|
|
|
|
var iteration_anchor = iteration.next;
|
|
|
|
anchor_key = neighbour && neighbour.key;
|
|
|
|
var key_anchor;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
anchor = iteration_anchor && iteration_anchor.first;
|
|
|
|
|
|
|
|
iteration_anchor = iteration_anchor && iteration_anchor.next;
|
|
|
|
|
|
|
|
key_anchor = iteration_anchor && iteration_anchor.key;
|
|
|
|
|
|
|
|
} while(iteration_anchor && key_anchor != key_next_iteration && !keep[key_anchor])
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
anchor = next_iteration && next_iteration.first;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
anchor = next && next.first;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
iteration[intro_method](node, anchor);
|
|
|
|
block[intro_method](node, anchor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
iteration.next = next;
|
|
|
|
iteration.next = next_iteration;
|
|
|
|
if (next) next.last = iteration;
|
|
|
|
if (next_iteration) next_iteration.last = iteration;
|
|
|
|
next = iteration;
|
|
|
|
next_iteration = iteration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|