holy shit i think i did it

pull/1274/head
Rich-Harris 7 years ago
parent 7c953a6622
commit a3e91eb267

@ -56,20 +56,12 @@ export function updateKeyedEach(component, key, changed, key_prop, dynamic, list
var will_move = {};
var did_move = {};
var r = 100;
console.log('deltas', deltas);
while (o && n) {
if (!--r) throw new Error('hmm');
var item = list[n - 1];
var new_key = item[key_prop];
var old_key = old_keys[o - 1];
console.log(`${old_keys.slice(0, o - 1).join('')}[${old_key}]${old_keys.slice(o).join('')} ${new_keys.slice(0, n - 1)}[${new_key}]${new_keys.slice(n)}`);
if (new_key === old_key) {
console.log('SAME SAME');
o--;
n--;
@ -78,14 +70,12 @@ export function updateKeyedEach(component, key, changed, key_prop, dynamic, list
else if (lookup[old_key] && !new_blocks[old_key]) {
// removing
console.log(`removing ${old_key}`);
destroyIteration(lookup[old_key], lookup);
o--;
}
else if (!lookup[new_key]) {
// creating
console.log(`adding ${new_key}`);
new_blocks[new_key][intro_method](node, next && next.first);
next = new_blocks[new_key];
lookup[new_key] = new_blocks[new_key];
@ -93,42 +83,28 @@ export function updateKeyedEach(component, key, changed, key_prop, dynamic, list
}
else if (lookup[old_key] && lookup[new_key]) {
console.log('both previously existed');
if (did_move[old_key]) {
console.log('did move', old_key);
o--;
// next = new_blocks[old_key];
} else if (will_move[new_key]) {
console.log('moving', new_key);
new_blocks[new_key][intro_method](node, next && next.first);
next = new_blocks[new_key];
n--;
} else if (deltas[new_key] > deltas[old_key]) {
// we already have both blocks, but they're out of order
console.log('inserting', new_key);
new_blocks[new_key][intro_method](node, next && next.first);
next = new_blocks[new_key];
did_move[new_key] = true;
n--;
} else {
console.log('will move', old_key);
will_move[old_key] = true;
o--;
}
}
else {
throw new Error('???');
}
console.log(document.body.textContent);
console.log(`next is ${next && next.key}\n`);
}
console.log({ will_move: Object.keys(will_move) });
while (o--) {
var old_key = old_keys[o];
if (!new_blocks[old_key]) destroyIteration(lookup[old_key], lookup);

@ -22,46 +22,42 @@ export default {
allowES2015: true,
data: {
values: toObjects('duqbmineapjhtlofrskcg'),
values: toObjects('abc'),
},
// html: `(a)(b)(c)`,
html: `(a)(b)(c)`,
test(assert, component, target) {
function test(sequence) {
const previous = target.textContent;
console.group(`${previous.replace(/[()]/g, '')} -> ${sequence}`);
const expected = sequence.split('').map(x => `(${x})`).join('');
component.set({ values: toObjects(sequence) });
console.log(`result: ${target.textContent.replace(/[()]/g, '')}`);
assert.htmlEqual(
target.innerHTML,
expected,
`\n${previous} -> ${expected}\n${target.textContent}`
);
console.groupEnd();
}
// first, some fixed tests so that we can debug them
// test('abc');
// test('abcd');
// test('abecd');
// test('fabecd');
// test('fabed');
// test('beadf');
// test('ghbeadf');
// test('gf');
// test('gc');
// test('g');
// test('');
// test('abc');
// test('duqbmineapjhtlofrskcg');
test('abc');
test('abcd');
test('abecd');
test('fabecd');
test('fabed');
test('beadf');
test('ghbeadf');
test('gf');
test('gc');
test('g');
test('');
test('abc');
test('duqbmineapjhtlofrskcg');
test('hdnkjougmrvftewsqpailcb');
test('bidhfacge');
test('kgjnempcboaflidh');
test('fekbijachgd');
test('kdmlgfbicheja');
return;
// then, we party
for (let i = 0; i < 1000; i += 1) test(permute());

Loading…
Cancel
Save