mirror of
https://github.com/sveltejs/svelte.git
synced 2024-12-01 17:30:59 +01:00
remove linked list stuff
This commit is contained in:
parent
174975c93e
commit
f4145099f4
@ -246,14 +246,11 @@ export default class EachBlock extends Node {
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const key = block.getUniqueName('key');
|
const key = block.getUniqueName('key');
|
||||||
|
const blocks = block.getUniqueName(`${each}_blocks`);
|
||||||
const lookup = block.getUniqueName(`${each}_lookup`);
|
const lookup = block.getUniqueName(`${each}_lookup`);
|
||||||
const iteration = block.getUniqueName(`${each}_iteration`);
|
|
||||||
const head = block.getUniqueName(`${each}_head`);
|
|
||||||
const last = block.getUniqueName(`${each}_last`);
|
|
||||||
|
|
||||||
|
block.addVariable(blocks, '[]');
|
||||||
block.addVariable(lookup, `@blankObject()`);
|
block.addVariable(lookup, `@blankObject()`);
|
||||||
block.addVariable(head);
|
|
||||||
block.addVariable(last);
|
|
||||||
|
|
||||||
if (this.children[0].isDomNode()) {
|
if (this.children[0].isDomNode()) {
|
||||||
this.block.first = this.children[0].var;
|
this.block.first = this.children[0].var;
|
||||||
@ -270,14 +267,9 @@ export default class EachBlock extends Node {
|
|||||||
block.builders.init.addBlock(deindent`
|
block.builders.init.addBlock(deindent`
|
||||||
for (var #i = 0; #i < ${each_block_value}.${length}; #i += 1) {
|
for (var #i = 0; #i < ${each_block_value}.${length}; #i += 1) {
|
||||||
var ${key} = ${each_block_value}[#i].${this.key};
|
var ${key} = ${each_block_value}[#i].${this.key};
|
||||||
var ${iteration} = ${lookup}[${key}] = ${create_each_block}(#component, ${key}, @assign({}, state, {
|
${blocks}[#i] = ${lookup}[${key}] = ${create_each_block}(#component, ${key}, @assign({}, state, {
|
||||||
${this.contextProps.join(',\n')}
|
${this.contextProps.join(',\n')}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
if (${last}) ${last}.next = ${iteration};
|
|
||||||
${last} = ${iteration};
|
|
||||||
|
|
||||||
if (#i === 0) ${head} = ${iteration};
|
|
||||||
}
|
}
|
||||||
`);
|
`);
|
||||||
|
|
||||||
@ -286,29 +278,17 @@ export default class EachBlock extends Node {
|
|||||||
const anchorNode = parentNode ? 'null' : 'anchor';
|
const anchorNode = parentNode ? 'null' : 'anchor';
|
||||||
|
|
||||||
block.builders.create.addBlock(deindent`
|
block.builders.create.addBlock(deindent`
|
||||||
var ${iteration} = ${head};
|
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].c();
|
||||||
while (${iteration}) {
|
|
||||||
${iteration}.c();
|
|
||||||
${iteration} = ${iteration}.next;
|
|
||||||
}
|
|
||||||
`);
|
`);
|
||||||
|
|
||||||
if (parentNodes) {
|
if (parentNodes) {
|
||||||
block.builders.claim.addBlock(deindent`
|
block.builders.claim.addBlock(deindent`
|
||||||
var ${iteration} = ${head};
|
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].l(${parentNodes});
|
||||||
while (${iteration}) {
|
|
||||||
${iteration}.l(${parentNodes});
|
|
||||||
${iteration} = ${iteration}.next;
|
|
||||||
}
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
block.builders.mount.addBlock(deindent`
|
block.builders.mount.addBlock(deindent`
|
||||||
var ${iteration} = ${head};
|
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].${mountOrIntro}(${initialMountNode}, ${anchorNode});
|
||||||
while (${iteration}) {
|
|
||||||
${iteration}.${mountOrIntro}(${initialMountNode}, ${anchorNode});
|
|
||||||
${iteration} = ${iteration}.next;
|
|
||||||
}
|
|
||||||
`);
|
`);
|
||||||
|
|
||||||
const dynamic = this.block.hasUpdateMethod;
|
const dynamic = this.block.hasUpdateMethod;
|
||||||
@ -316,31 +296,21 @@ export default class EachBlock extends Node {
|
|||||||
block.builders.update.addBlock(deindent`
|
block.builders.update.addBlock(deindent`
|
||||||
var ${each_block_value} = ${snippet};
|
var ${each_block_value} = ${snippet};
|
||||||
|
|
||||||
@updateKeyedEach(#component, ${key}, changed, "${this.key}", ${dynamic}, ${each_block_value}, ${head}, ${lookup}, ${updateMountNode}, ${String(this.block.hasOutroMethod)}, ${create_each_block}, "${mountOrIntro}", function(#i) {
|
${blocks} = @updateKeyedEach(${blocks}, #component, ${key}, changed, "${this.key}", ${dynamic}, ${each_block_value}, ${lookup}, ${updateMountNode}, ${String(this.block.hasOutroMethod)}, ${create_each_block}, "${mountOrIntro}", function(#i) {
|
||||||
return @assign({}, state, {
|
return @assign({}, state, {
|
||||||
${this.contextProps.join(',\n')}
|
${this.contextProps.join(',\n')}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
${head} = ${lookup}[${each_block_value}[0] && ${each_block_value}[0].${this.key}];
|
|
||||||
`);
|
`);
|
||||||
|
|
||||||
if (!parentNode) {
|
if (!parentNode) {
|
||||||
block.builders.unmount.addBlock(deindent`
|
block.builders.unmount.addBlock(deindent`
|
||||||
var ${iteration} = ${head};
|
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].u();
|
||||||
while (${iteration}) {
|
|
||||||
${iteration}.u();
|
|
||||||
${iteration} = ${iteration}.next;
|
|
||||||
}
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
block.builders.destroy.addBlock(deindent`
|
block.builders.destroy.addBlock(deindent`
|
||||||
var ${iteration} = ${head};
|
for (#i = 0; #i < ${blocks}.length; #i += 1) ${blocks}[#i].d();
|
||||||
while (${iteration}) {
|
|
||||||
${iteration}.d();
|
|
||||||
${iteration} = ${iteration}.next;
|
|
||||||
}
|
|
||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,16 +17,13 @@ export function outroAndDestroyIteration(iteration, lookup) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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(blocks, component, key, changed, key_prop, dynamic, list, lookup, node, has_outro, create_each_block, intro_method, get_context) {
|
||||||
var old_indexes = {};
|
var old_indexes = {};
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
var old_keys = [];
|
var old_keys = blocks.map(function(block) {
|
||||||
while (head) {
|
return block.key;
|
||||||
old_keys.push(head.key);
|
});
|
||||||
old_indexes[head.key] = i++;
|
|
||||||
head = head.next;
|
|
||||||
}
|
|
||||||
|
|
||||||
var o = old_keys.length;
|
var o = old_keys.length;
|
||||||
var n = list.length;
|
var n = list.length;
|
||||||
@ -114,17 +111,10 @@ export function updateKeyedEach(component, key, changed, key_prop, dynamic, list
|
|||||||
while (n--) {
|
while (n--) {
|
||||||
var key = list[n][key_prop];
|
var key = list[n][key_prop];
|
||||||
new_blocks[key][intro_method](node, next && next.first);
|
new_blocks[key][intro_method](node, next && next.first);
|
||||||
next = new_blocks[key];
|
next = lookup[key] = new_blocks[key];
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO keep track of keys, so this is unnecessary
|
return list.map(function(item) {
|
||||||
var next = null;
|
return new_blocks[item[key_prop]];
|
||||||
var i = list.length;
|
});
|
||||||
while (i--) {
|
|
||||||
var key = list[i][key_prop];
|
|
||||||
var block = lookup[key] = new_blocks[key];
|
|
||||||
|
|
||||||
block.next = next;
|
|
||||||
next = block;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user