From a3e91eb267aaacf6611c956e1e71f1ed53ee86f1 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 23 Mar 2018 08:50:16 -0400 Subject: [PATCH] holy shit i think i did it --- src/shared/keyed-each.js | 26 +------------- .../_config.js | 34 ++++++++----------- 2 files changed, 16 insertions(+), 44 deletions(-) diff --git a/src/shared/keyed-each.js b/src/shared/keyed-each.js index e721840955..abea64ab44 100644 --- a/src/shared/keyed-each.js +++ b/src/shared/keyed-each.js @@ -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); diff --git a/test/runtime/samples/each-block-keyed-random-permute/_config.js b/test/runtime/samples/each-block-keyed-random-permute/_config.js index af6550be74..f14f822366 100644 --- a/test/runtime/samples/each-block-keyed-random-permute/_config.js +++ b/test/runtime/samples/each-block-keyed-random-permute/_config.js @@ -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());