|
|
@ -5,8 +5,11 @@ export default {
|
|
|
|
enter ( generator, node ) {
|
|
|
|
enter ( generator, node ) {
|
|
|
|
const i = generator.counters.each++;
|
|
|
|
const i = generator.counters.each++;
|
|
|
|
const name = `eachBlock_${i}`;
|
|
|
|
const name = `eachBlock_${i}`;
|
|
|
|
|
|
|
|
const elseName = `${name}_else`;
|
|
|
|
const iterations = `${name}_iterations`;
|
|
|
|
const iterations = `${name}_iterations`;
|
|
|
|
const renderer = `renderEachBlock_${i}`;
|
|
|
|
const renderer = `renderEachBlock_${i}`;
|
|
|
|
|
|
|
|
const renderElse = `${renderer}_else`;
|
|
|
|
|
|
|
|
const { params } = generator.current;
|
|
|
|
|
|
|
|
|
|
|
|
const listName = `${name}_value`;
|
|
|
|
const listName = `${name}_value`;
|
|
|
|
|
|
|
|
|
|
|
@ -21,12 +24,21 @@ export default {
|
|
|
|
generator.current.initStatements.push( deindent`
|
|
|
|
generator.current.initStatements.push( deindent`
|
|
|
|
var ${name}_value = ${snippet};
|
|
|
|
var ${name}_value = ${snippet};
|
|
|
|
var ${iterations} = [];
|
|
|
|
var ${iterations} = [];
|
|
|
|
|
|
|
|
${node.else ? `var ${elseName} = null;` : ''}
|
|
|
|
|
|
|
|
|
|
|
|
for ( var i = 0; i < ${name}_value.length; i += 1 ) {
|
|
|
|
for ( var i = 0; i < ${name}_value.length; i += 1 ) {
|
|
|
|
${iterations}[i] = ${renderer}( ${generator.current.params}, ${listName}, ${listName}[i], i, component );
|
|
|
|
${iterations}[i] = ${renderer}( ${params}, ${listName}, ${listName}[i], i, component );
|
|
|
|
${!isToplevel ? `${iterations}[i].mount( ${anchor}.parentNode, ${anchor} );` : ''}
|
|
|
|
${!isToplevel ? `${iterations}[i].mount( ${anchor}.parentNode, ${anchor} );` : ''}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
` );
|
|
|
|
` );
|
|
|
|
|
|
|
|
if ( node.else ) {
|
|
|
|
|
|
|
|
generator.current.initStatements.push( deindent`
|
|
|
|
|
|
|
|
if ( !${name}_value.length ) {
|
|
|
|
|
|
|
|
${elseName} = ${renderElse}( ${params}, component );
|
|
|
|
|
|
|
|
${!isToplevel ? `${elseName}.mount( ${anchor}.parentNode, ${anchor} );` : ''}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
` );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( isToplevel ) {
|
|
|
|
if ( isToplevel ) {
|
|
|
|
generator.current.mountStatements.push( deindent`
|
|
|
|
generator.current.mountStatements.push( deindent`
|
|
|
@ -34,6 +46,13 @@ export default {
|
|
|
|
${iterations}[i].mount( ${anchor}.parentNode, ${anchor} );
|
|
|
|
${iterations}[i].mount( ${anchor}.parentNode, ${anchor} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
` );
|
|
|
|
` );
|
|
|
|
|
|
|
|
if ( node.else ) {
|
|
|
|
|
|
|
|
generator.current.mountStatements.push( deindent`
|
|
|
|
|
|
|
|
if ( ${elseName} ) {
|
|
|
|
|
|
|
|
${elseName}.mount( ${anchor}.parentNode, ${anchor} );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
` );
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
generator.current.updateStatements.push( deindent`
|
|
|
|
generator.current.updateStatements.push( deindent`
|
|
|
@ -41,10 +60,10 @@ export default {
|
|
|
|
|
|
|
|
|
|
|
|
for ( var i = 0; i < ${name}_value.length; i += 1 ) {
|
|
|
|
for ( var i = 0; i < ${name}_value.length; i += 1 ) {
|
|
|
|
if ( !${iterations}[i] ) {
|
|
|
|
if ( !${iterations}[i] ) {
|
|
|
|
${iterations}[i] = ${renderer}( ${generator.current.params}, ${listName}, ${listName}[i], i, component );
|
|
|
|
${iterations}[i] = ${renderer}( ${params}, ${listName}, ${listName}[i], i, component );
|
|
|
|
${iterations}[i].mount( ${anchor}.parentNode, ${anchor} );
|
|
|
|
${iterations}[i].mount( ${anchor}.parentNode, ${anchor} );
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${iterations}[i].update( changed, ${generator.current.params}, ${listName}, ${listName}[i], i );
|
|
|
|
${iterations}[i].update( changed, ${params}, ${listName}, ${listName}[i], i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -54,12 +73,51 @@ export default {
|
|
|
|
|
|
|
|
|
|
|
|
${iterations}.length = ${listName}.length;
|
|
|
|
${iterations}.length = ${listName}.length;
|
|
|
|
` );
|
|
|
|
` );
|
|
|
|
|
|
|
|
if ( node.else ) {
|
|
|
|
|
|
|
|
generator.current.updateStatements.push( deindent`
|
|
|
|
|
|
|
|
if ( !${name}_value.length && ${elseName} ) {
|
|
|
|
|
|
|
|
${elseName}.update( changed, ${params} );
|
|
|
|
|
|
|
|
} else if ( !${name}_value.length ) {
|
|
|
|
|
|
|
|
${elseName} = ${renderElse}( ${params}, component );
|
|
|
|
|
|
|
|
${elseName}.mount( ${anchor}.parentNode, ${anchor} );
|
|
|
|
|
|
|
|
} else if ( ${elseName} ) {
|
|
|
|
|
|
|
|
${elseName}.teardown( true );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
` );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
generator.current.teardownStatements.push( deindent`
|
|
|
|
generator.current.teardownStatements.push( deindent`
|
|
|
|
for ( var i = 0; i < ${iterations}.length; i += 1 ) {
|
|
|
|
for ( var i = 0; i < ${iterations}.length; i += 1 ) {
|
|
|
|
${iterations}[i].teardown( ${isToplevel ? 'detach' : 'false'} );
|
|
|
|
${iterations}[i].teardown( ${isToplevel ? 'detach' : 'false'} );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
` );
|
|
|
|
` );
|
|
|
|
|
|
|
|
if ( node.else ) {
|
|
|
|
|
|
|
|
generator.current.teardownStatements.push( deindent`
|
|
|
|
|
|
|
|
if ( ${elseName} ) {
|
|
|
|
|
|
|
|
${elseName}.teardown( ${isToplevel ? 'detach' : 'false'} );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
` );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( node.else ) {
|
|
|
|
|
|
|
|
generator.push({
|
|
|
|
|
|
|
|
useAnchor: false,
|
|
|
|
|
|
|
|
name: renderElse,
|
|
|
|
|
|
|
|
target: 'target',
|
|
|
|
|
|
|
|
localElementDepth: 0,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initStatements: [],
|
|
|
|
|
|
|
|
mountStatements: [],
|
|
|
|
|
|
|
|
updateStatements: [],
|
|
|
|
|
|
|
|
detachStatements: [],
|
|
|
|
|
|
|
|
teardownStatements: [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
counter: counter()
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
node.else.children.forEach( generator.visit );
|
|
|
|
|
|
|
|
generator.addRenderer( generator.current );
|
|
|
|
|
|
|
|
generator.pop();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const indexNames = Object.assign( {}, generator.current.indexNames );
|
|
|
|
const indexNames = Object.assign( {}, generator.current.indexNames );
|
|
|
|
const indexName = indexNames[ node.context ] = ( node.index || `${node.context}__index` );
|
|
|
|
const indexName = indexNames[ node.context ] = ( node.index || `${node.context}__index` );
|
|
|
@ -76,7 +134,7 @@ export default {
|
|
|
|
const contextDependencies = Object.assign( {}, generator.current.contextDependencies );
|
|
|
|
const contextDependencies = Object.assign( {}, generator.current.contextDependencies );
|
|
|
|
contextDependencies[ node.context ] = dependencies;
|
|
|
|
contextDependencies[ node.context ] = dependencies;
|
|
|
|
|
|
|
|
|
|
|
|
const params = generator.current.params + `, ${listName}, ${node.context}, ${indexName}`;
|
|
|
|
const blockParams = generator.current.params + `, ${listName}, ${node.context}, ${indexName}`;
|
|
|
|
|
|
|
|
|
|
|
|
generator.push({
|
|
|
|
generator.push({
|
|
|
|
useAnchor: false,
|
|
|
|
useAnchor: false,
|
|
|
@ -92,7 +150,7 @@ export default {
|
|
|
|
|
|
|
|
|
|
|
|
indexNames,
|
|
|
|
indexNames,
|
|
|
|
listNames,
|
|
|
|
listNames,
|
|
|
|
params,
|
|
|
|
params: blockParams,
|
|
|
|
|
|
|
|
|
|
|
|
initStatements: [],
|
|
|
|
initStatements: [],
|
|
|
|
mountStatements: [],
|
|
|
|
mountStatements: [],
|
|
|
|