|
|
@ -15,7 +15,6 @@ export default function visitEachBlock(
|
|
|
|
const create_each_block = node._block.name;
|
|
|
|
const create_each_block = node._block.name;
|
|
|
|
const each_block_value = node._block.listName;
|
|
|
|
const each_block_value = node._block.listName;
|
|
|
|
const iterations = block.getUniqueName(`${each_block}_iterations`);
|
|
|
|
const iterations = block.getUniqueName(`${each_block}_iterations`);
|
|
|
|
const i = block.alias(`i`);
|
|
|
|
|
|
|
|
const params = block.params.join(', ');
|
|
|
|
const params = block.params.join(', ');
|
|
|
|
const anchor = node.needsAnchor
|
|
|
|
const anchor = node.needsAnchor
|
|
|
|
? block.getUniqueName(`${each_block}_anchor`)
|
|
|
|
? block.getUniqueName(`${each_block}_anchor`)
|
|
|
@ -27,7 +26,6 @@ export default function visitEachBlock(
|
|
|
|
create_each_block,
|
|
|
|
create_each_block,
|
|
|
|
each_block_value,
|
|
|
|
each_block_value,
|
|
|
|
iterations,
|
|
|
|
iterations,
|
|
|
|
i,
|
|
|
|
|
|
|
|
params,
|
|
|
|
params,
|
|
|
|
anchor,
|
|
|
|
anchor,
|
|
|
|
mountOrIntro,
|
|
|
|
mountOrIntro,
|
|
|
@ -138,7 +136,6 @@ function keyed(
|
|
|
|
each_block,
|
|
|
|
each_block,
|
|
|
|
create_each_block,
|
|
|
|
create_each_block,
|
|
|
|
each_block_value,
|
|
|
|
each_block_value,
|
|
|
|
i,
|
|
|
|
|
|
|
|
params,
|
|
|
|
params,
|
|
|
|
anchor,
|
|
|
|
anchor,
|
|
|
|
mountOrIntro,
|
|
|
|
mountOrIntro,
|
|
|
@ -170,15 +167,15 @@ function keyed(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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}].${node.key};
|
|
|
|
var ${key} = ${each_block_value}[#i].${node.key};
|
|
|
|
var ${iteration} = ${lookup}[${key}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component}, ${key} );
|
|
|
|
var ${iteration} = ${lookup}[${key}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[#i], #i, ${block.component}, ${key} );
|
|
|
|
|
|
|
|
|
|
|
|
if ( ${last} ) ${last}.next = ${iteration};
|
|
|
|
if ( ${last} ) ${last}.next = ${iteration};
|
|
|
|
${iteration}.last = ${last};
|
|
|
|
${iteration}.last = ${last};
|
|
|
|
${last} = ${iteration};
|
|
|
|
${last} = ${iteration};
|
|
|
|
|
|
|
|
|
|
|
|
if ( ${i} === 0 ) ${head} = ${iteration};
|
|
|
|
if ( #i === 0 ) ${head} = ${iteration};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
@ -231,9 +228,9 @@ function keyed(
|
|
|
|
${expected} = ${expected}.next;
|
|
|
|
${expected} = ${expected}.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for ( ${i} = 0; ${i} < discard_pile.length; ${i} += 1 ) {
|
|
|
|
for ( #i = 0; #i < discard_pile.length; #i += 1 ) {
|
|
|
|
if ( discard_pile[${i}].discard ) {
|
|
|
|
if ( discard_pile[#i].discard ) {
|
|
|
|
${fn}( discard_pile[${i}] );
|
|
|
|
${fn}( discard_pile[#i] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
`;
|
|
|
@ -253,8 +250,8 @@ function keyed(
|
|
|
|
${expected} = ${expected}.next;
|
|
|
|
${expected} = ${expected}.next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for ( ${i} = 0; ${i} < discard_pile.length; ${i} += 1 ) {
|
|
|
|
for ( #i = 0; #i < discard_pile.length; #i += 1 ) {
|
|
|
|
var ${iteration} = discard_pile[${i}];
|
|
|
|
var ${iteration} = discard_pile[#i];
|
|
|
|
if ( ${iteration}.discard ) {
|
|
|
|
if ( ${iteration}.discard ) {
|
|
|
|
${fn}( ${iteration} );
|
|
|
|
${fn}( ${iteration} );
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -270,12 +267,12 @@ function keyed(
|
|
|
|
|
|
|
|
|
|
|
|
var discard_pile = [];
|
|
|
|
var discard_pile = [];
|
|
|
|
|
|
|
|
|
|
|
|
for ( ${i} = 0; ${i} < ${each_block_value}.length; ${i} += 1 ) {
|
|
|
|
for ( #i = 0; #i < ${each_block_value}.length; #i += 1 ) {
|
|
|
|
var ${key} = ${each_block_value}[${i}].${node.key};
|
|
|
|
var ${key} = ${each_block_value}[#i].${node.key};
|
|
|
|
var ${iteration} = ${lookup}[${key}];
|
|
|
|
var ${iteration} = ${lookup}[${key}];
|
|
|
|
|
|
|
|
|
|
|
|
${dynamic &&
|
|
|
|
${dynamic &&
|
|
|
|
`if ( ${iteration} ) ${iteration}.update( changed, ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i} );`}
|
|
|
|
`if ( ${iteration} ) ${iteration}.update( changed, ${params}, ${each_block_value}, ${each_block_value}[#i], #i );`}
|
|
|
|
|
|
|
|
|
|
|
|
if ( ${expected} ) {
|
|
|
|
if ( ${expected} ) {
|
|
|
|
if ( ${key} === ${expected}.key ) {
|
|
|
|
if ( ${key} === ${expected}.key ) {
|
|
|
@ -296,7 +293,7 @@ function keyed(
|
|
|
|
if (!${expected}) ${iteration}.mount( ${parentNode}, ${anchor} );
|
|
|
|
if (!${expected}) ${iteration}.mount( ${parentNode}, ${anchor} );
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// key is being inserted
|
|
|
|
// key is being inserted
|
|
|
|
${iteration} = ${lookup}[${key}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component}, ${key} );
|
|
|
|
${iteration} = ${lookup}[${key}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[#i], #i, ${block.component}, ${key} );
|
|
|
|
${iteration}.create();
|
|
|
|
${iteration}.create();
|
|
|
|
${iteration}.${mountOrIntro}( ${parentNode}, ${expected}.first );
|
|
|
|
${iteration}.${mountOrIntro}( ${parentNode}, ${expected}.first );
|
|
|
|
|
|
|
|
|
|
|
@ -311,7 +308,7 @@ function keyed(
|
|
|
|
${iteration}.next = null;
|
|
|
|
${iteration}.next = null;
|
|
|
|
${iteration}.mount( ${parentNode}, ${anchor} );
|
|
|
|
${iteration}.mount( ${parentNode}, ${anchor} );
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${iteration} = ${lookup}[${key}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component}, ${key} );
|
|
|
|
${iteration} = ${lookup}[${key}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[#i], #i, ${block.component}, ${key} );
|
|
|
|
${iteration}.create();
|
|
|
|
${iteration}.create();
|
|
|
|
${iteration}.${mountOrIntro}( ${parentNode}, ${anchor} );
|
|
|
|
${iteration}.${mountOrIntro}( ${parentNode}, ${anchor} );
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -360,7 +357,6 @@ function unkeyed(
|
|
|
|
create_each_block,
|
|
|
|
create_each_block,
|
|
|
|
each_block_value,
|
|
|
|
each_block_value,
|
|
|
|
iterations,
|
|
|
|
iterations,
|
|
|
|
i,
|
|
|
|
|
|
|
|
params,
|
|
|
|
params,
|
|
|
|
anchor,
|
|
|
|
anchor,
|
|
|
|
mountOrIntro,
|
|
|
|
mountOrIntro,
|
|
|
@ -369,8 +365,8 @@ function unkeyed(
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
var ${iterations} = [];
|
|
|
|
var ${iterations} = [];
|
|
|
|
|
|
|
|
|
|
|
|
for ( var ${i} = 0; ${i} < ${each_block_value}.length; ${i} += 1 ) {
|
|
|
|
for ( var #i = 0; #i < ${each_block_value}.length; #i += 1 ) {
|
|
|
|
${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} );
|
|
|
|
${iterations}[#i] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[#i], #i, ${block.component} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
@ -378,20 +374,20 @@ function unkeyed(
|
|
|
|
const anchorNode = state.parentNode ? 'null' : 'anchor';
|
|
|
|
const anchorNode = state.parentNode ? 'null' : 'anchor';
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.create.addBlock(deindent`
|
|
|
|
block.builders.create.addBlock(deindent`
|
|
|
|
for ( var ${i} = 0; ${i} < ${iterations}.length; ${i} += 1 ) {
|
|
|
|
for ( var #i = 0; #i < ${iterations}.length; #i += 1 ) {
|
|
|
|
${iterations}[${i}].create();
|
|
|
|
${iterations}[#i].create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.claim.addBlock(deindent`
|
|
|
|
block.builders.claim.addBlock(deindent`
|
|
|
|
for ( var ${i} = 0; ${i} < ${iterations}.length; ${i} += 1 ) {
|
|
|
|
for ( var #i = 0; #i < ${iterations}.length; #i += 1 ) {
|
|
|
|
${iterations}[${i}].claim( ${state.parentNodes} );
|
|
|
|
${iterations}[#i].claim( ${state.parentNodes} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.mount.addBlock(deindent`
|
|
|
|
block.builders.mount.addBlock(deindent`
|
|
|
|
for ( var ${i} = 0; ${i} < ${iterations}.length; ${i} += 1 ) {
|
|
|
|
for ( var #i = 0; #i < ${iterations}.length; #i += 1 ) {
|
|
|
|
${iterations}[${i}].${mountOrIntro}( ${targetNode}, ${anchorNode} );
|
|
|
|
${iterations}[#i].${mountOrIntro}( ${targetNode}, ${anchorNode} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
@ -412,26 +408,26 @@ function unkeyed(
|
|
|
|
const forLoopBody = node._block.hasUpdateMethod
|
|
|
|
const forLoopBody = node._block.hasUpdateMethod
|
|
|
|
? node._block.hasIntroMethod
|
|
|
|
? node._block.hasIntroMethod
|
|
|
|
? deindent`
|
|
|
|
? deindent`
|
|
|
|
if ( ${iterations}[${i}] ) {
|
|
|
|
if ( ${iterations}[#i] ) {
|
|
|
|
${iterations}[${i}].update( changed, ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i} );
|
|
|
|
${iterations}[#i].update( changed, ${params}, ${each_block_value}, ${each_block_value}[#i], #i );
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} );
|
|
|
|
${iterations}[#i] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[#i], #i, ${block.component} );
|
|
|
|
${iterations}[${i}].create();
|
|
|
|
${iterations}[#i].create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${iterations}[${i}].intro( ${parentNode}, ${anchor} );
|
|
|
|
${iterations}[#i].intro( ${parentNode}, ${anchor} );
|
|
|
|
`
|
|
|
|
`
|
|
|
|
: deindent`
|
|
|
|
: deindent`
|
|
|
|
if ( ${iterations}[${i}] ) {
|
|
|
|
if ( ${iterations}[#i] ) {
|
|
|
|
${iterations}[${i}].update( changed, ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i} );
|
|
|
|
${iterations}[#i].update( changed, ${params}, ${each_block_value}, ${each_block_value}[#i], #i );
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} );
|
|
|
|
${iterations}[#i] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[#i], #i, ${block.component} );
|
|
|
|
${iterations}[${i}].create();
|
|
|
|
${iterations}[#i].create();
|
|
|
|
${iterations}[${i}].mount( ${parentNode}, ${anchor} );
|
|
|
|
${iterations}[#i].mount( ${parentNode}, ${anchor} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
`
|
|
|
|
: deindent`
|
|
|
|
: deindent`
|
|
|
|
${iterations}[${i}] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[${i}], ${i}, ${block.component} );
|
|
|
|
${iterations}[#i] = ${create_each_block}( ${params}, ${each_block_value}, ${each_block_value}[#i], #i, ${block.component} );
|
|
|
|
${iterations}[${i}].${mountOrIntro}( ${parentNode}, ${anchor} );
|
|
|
|
${iterations}[#i].${mountOrIntro}( ${parentNode}, ${anchor} );
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const start = node._block.hasUpdateMethod ? '0' : `${iterations}.length`;
|
|
|
|
const start = node._block.hasUpdateMethod ? '0' : `${iterations}.length`;
|
|
|
@ -449,12 +445,12 @@ function unkeyed(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for ( ; ${i} < ${iterations}.length; ${i} += 1 ) ${outro}( ${i} );
|
|
|
|
for ( ; #i < ${iterations}.length; #i += 1 ) ${outro}( #i );
|
|
|
|
`
|
|
|
|
`
|
|
|
|
: deindent`
|
|
|
|
: deindent`
|
|
|
|
for ( ; ${i} < ${iterations}.length; ${i} += 1 ) {
|
|
|
|
for ( ; #i < ${iterations}.length; #i += 1 ) {
|
|
|
|
${iterations}[${i}].unmount();
|
|
|
|
${iterations}[#i].unmount();
|
|
|
|
${iterations}[${i}].destroy();
|
|
|
|
${iterations}[#i].destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${iterations}.length = ${each_block_value}.length;
|
|
|
|
${iterations}.length = ${each_block_value}.length;
|
|
|
|
`;
|
|
|
|
`;
|
|
|
@ -463,7 +459,7 @@ function unkeyed(
|
|
|
|
var ${each_block_value} = ${snippet};
|
|
|
|
var ${each_block_value} = ${snippet};
|
|
|
|
|
|
|
|
|
|
|
|
if ( ${condition} ) {
|
|
|
|
if ( ${condition} ) {
|
|
|
|
for ( var ${i} = ${start}; ${i} < ${each_block_value}.length; ${i} += 1 ) {
|
|
|
|
for ( var #i = ${start}; #i < ${each_block_value}.length; #i += 1 ) {
|
|
|
|
${forLoopBody}
|
|
|
|
${forLoopBody}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -473,8 +469,8 @@ function unkeyed(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.unmount.addBlock(deindent`
|
|
|
|
block.builders.unmount.addBlock(deindent`
|
|
|
|
for ( var ${i} = 0; ${i} < ${iterations}.length; ${i} += 1 ) {
|
|
|
|
for ( var #i = 0; #i < ${iterations}.length; #i += 1 ) {
|
|
|
|
${iterations}[${i}].unmount();
|
|
|
|
${iterations}[#i].unmount();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|