|
|
@ -226,21 +226,23 @@ function compound(
|
|
|
|
dynamic,
|
|
|
|
dynamic,
|
|
|
|
{ name, anchor, params, hasElse, if_name }
|
|
|
|
{ name, anchor, params, hasElse, if_name }
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
const get_block = block.getUniqueName(`get_block`);
|
|
|
|
const select_block_type = generator.getUniqueName(`select_block_type`);
|
|
|
|
const current_block = block.getUniqueName(`current_block`);
|
|
|
|
const current_block_type = block.getUniqueName(`current_block_type`);
|
|
|
|
const current_block_and = hasElse ? '' : `${current_block} && `;
|
|
|
|
const current_block_type_and = hasElse ? '' : `${current_block_type} && `;
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
generator.blocks.push(deindent`
|
|
|
|
function ${get_block} ( ${params} ) {
|
|
|
|
function ${select_block_type} ( ${params} ) {
|
|
|
|
${branches
|
|
|
|
${branches
|
|
|
|
.map(({ condition, block }) => {
|
|
|
|
.map(({ condition, block }) => {
|
|
|
|
return `${condition ? `if ( ${condition} ) ` : ''}return ${block};`;
|
|
|
|
return `${condition ? `if ( ${condition} ) ` : ''}return ${block};`;
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.join('\n')}
|
|
|
|
.join('\n')}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
var ${current_block} = ${get_block}( ${params} );
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
var ${name} = ${current_block_and}${current_block}( ${params}, #component );
|
|
|
|
var ${current_block_type} = ${select_block_type}( ${params} );
|
|
|
|
|
|
|
|
var ${name} = ${current_block_type_and}${current_block_type}( ${params}, #component );
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
|
|
|
|
|
|
|
|
const isTopLevel = !state.parentNode;
|
|
|
|
const isTopLevel = !state.parentNode;
|
|
|
@ -265,14 +267,14 @@ function compound(
|
|
|
|
${name}.unmount();
|
|
|
|
${name}.unmount();
|
|
|
|
${name}.destroy();
|
|
|
|
${name}.destroy();
|
|
|
|
}`}
|
|
|
|
}`}
|
|
|
|
${name} = ${current_block_and}${current_block}( ${params}, #component );
|
|
|
|
${name} = ${current_block_type_and}${current_block_type}( ${params}, #component );
|
|
|
|
${if_name}${name}.create();
|
|
|
|
${if_name}${name}.create();
|
|
|
|
${if_name}${name}.${mountOrIntro}( ${parentNode}, ${anchor} );
|
|
|
|
${if_name}${name}.${mountOrIntro}( ${parentNode}, ${anchor} );
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
if (dynamic) {
|
|
|
|
if (dynamic) {
|
|
|
|
block.builders.update.addBlock(deindent`
|
|
|
|
block.builders.update.addBlock(deindent`
|
|
|
|
if ( ${current_block} === ( ${current_block} = ${get_block}( ${params} ) ) && ${name} ) {
|
|
|
|
if ( ${current_block_type} === ( ${current_block_type} = ${select_block_type}( ${params} ) ) && ${name} ) {
|
|
|
|
${name}.update( changed, ${params} );
|
|
|
|
${name}.update( changed, ${params} );
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${changeBlock}
|
|
|
|
${changeBlock}
|
|
|
@ -280,7 +282,7 @@ function compound(
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
block.builders.update.addBlock(deindent`
|
|
|
|
block.builders.update.addBlock(deindent`
|
|
|
|
if ( ${current_block} !== ( ${current_block} = ${get_block}( ${params} ) ) ) {
|
|
|
|
if ( ${current_block_type} !== ( ${current_block_type} = ${select_block_type}( ${params} ) ) ) {
|
|
|
|
${changeBlock}
|
|
|
|
${changeBlock}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
@ -302,17 +304,17 @@ function compoundWithOutros(
|
|
|
|
dynamic,
|
|
|
|
dynamic,
|
|
|
|
{ name, anchor, params, hasElse }
|
|
|
|
{ name, anchor, params, hasElse }
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
const get_block = block.getUniqueName(`get_block`);
|
|
|
|
const select_block_type = block.getUniqueName(`select_block_type`);
|
|
|
|
const current_block_index = block.getUniqueName(`current_block_index`);
|
|
|
|
const current_block_type_index = block.getUniqueName(`current_block_type_index`);
|
|
|
|
const previous_block_index = block.getUniqueName(`previous_block_index`);
|
|
|
|
const previous_block_index = block.getUniqueName(`previous_block_index`);
|
|
|
|
const if_block_creators = block.getUniqueName(`if_block_creators`);
|
|
|
|
const if_block_creators = block.getUniqueName(`if_block_creators`);
|
|
|
|
const if_blocks = block.getUniqueName(`if_blocks`);
|
|
|
|
const if_blocks = block.getUniqueName(`if_blocks`);
|
|
|
|
|
|
|
|
|
|
|
|
const if_current_block_index = hasElse
|
|
|
|
const if_current_block_type_index = hasElse
|
|
|
|
? ''
|
|
|
|
? ''
|
|
|
|
: `if ( ~${current_block_index} ) `;
|
|
|
|
: `if ( ~${current_block_type_index} ) `;
|
|
|
|
|
|
|
|
|
|
|
|
block.addVariable(current_block_index);
|
|
|
|
block.addVariable(current_block_type_index);
|
|
|
|
block.addVariable(name);
|
|
|
|
block.addVariable(name);
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
@ -322,7 +324,7 @@ function compoundWithOutros(
|
|
|
|
|
|
|
|
|
|
|
|
var ${if_blocks} = [];
|
|
|
|
var ${if_blocks} = [];
|
|
|
|
|
|
|
|
|
|
|
|
function ${get_block} ( ${params} ) {
|
|
|
|
function ${select_block_type} ( ${params} ) {
|
|
|
|
${branches
|
|
|
|
${branches
|
|
|
|
.map(({ condition, block }, i) => {
|
|
|
|
.map(({ condition, block }, i) => {
|
|
|
|
return `${condition ? `if ( ${condition} ) ` : ''}return ${block
|
|
|
|
return `${condition ? `if ( ${condition} ) ` : ''}return ${block
|
|
|
@ -335,13 +337,13 @@ function compoundWithOutros(
|
|
|
|
|
|
|
|
|
|
|
|
if (hasElse) {
|
|
|
|
if (hasElse) {
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
${current_block_index} = ${get_block}( ${params} );
|
|
|
|
${current_block_type_index} = ${select_block_type}( ${params} );
|
|
|
|
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, #component );
|
|
|
|
${name} = ${if_blocks}[ ${current_block_type_index} ] = ${if_block_creators}[ ${current_block_type_index} ]( ${params}, #component );
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
block.builders.init.addBlock(deindent`
|
|
|
|
if ( ~( ${current_block_index} = ${get_block}( ${params} ) ) ) {
|
|
|
|
if ( ~( ${current_block_type_index} = ${select_block_type}( ${params} ) ) ) {
|
|
|
|
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, #component );
|
|
|
|
${name} = ${if_blocks}[ ${current_block_type_index} ] = ${if_block_creators}[ ${current_block_type_index} ]( ${params}, #component );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -352,7 +354,7 @@ function compoundWithOutros(
|
|
|
|
const anchorNode = state.parentNode ? 'null' : 'anchor';
|
|
|
|
const anchorNode = state.parentNode ? 'null' : 'anchor';
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.mount.addLine(
|
|
|
|
block.builders.mount.addLine(
|
|
|
|
`${if_current_block_index}${if_blocks}[ ${current_block_index} ].${mountOrIntro}( ${targetNode}, ${anchorNode} );`
|
|
|
|
`${if_current_block_type_index}${if_blocks}[ ${current_block_type_index} ].${mountOrIntro}( ${targetNode}, ${anchorNode} );`
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const parentNode = state.parentNode || `${anchor}.parentNode`;
|
|
|
|
const parentNode = state.parentNode || `${anchor}.parentNode`;
|
|
|
@ -366,9 +368,9 @@ function compoundWithOutros(
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
const createNewBlock = deindent`
|
|
|
|
const createNewBlock = deindent`
|
|
|
|
${name} = ${if_blocks}[ ${current_block_index} ];
|
|
|
|
${name} = ${if_blocks}[ ${current_block_type_index} ];
|
|
|
|
if ( !${name} ) {
|
|
|
|
if ( !${name} ) {
|
|
|
|
${name} = ${if_blocks}[ ${current_block_index} ] = ${if_block_creators}[ ${current_block_index} ]( ${params}, #component );
|
|
|
|
${name} = ${if_blocks}[ ${current_block_type_index} ] = ${if_block_creators}[ ${current_block_type_index} ]( ${params}, #component );
|
|
|
|
${name}.create();
|
|
|
|
${name}.create();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
${name}.${mountOrIntro}( ${parentNode}, ${anchor} );
|
|
|
|
${name}.${mountOrIntro}( ${parentNode}, ${anchor} );
|
|
|
@ -385,7 +387,7 @@ function compoundWithOutros(
|
|
|
|
${destroyOldBlock}
|
|
|
|
${destroyOldBlock}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ( ~${current_block_index} ) {
|
|
|
|
if ( ~${current_block_type_index} ) {
|
|
|
|
${createNewBlock}
|
|
|
|
${createNewBlock}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${name} = null;
|
|
|
|
${name} = null;
|
|
|
@ -394,28 +396,28 @@ function compoundWithOutros(
|
|
|
|
|
|
|
|
|
|
|
|
if (dynamic) {
|
|
|
|
if (dynamic) {
|
|
|
|
block.builders.update.addBlock(deindent`
|
|
|
|
block.builders.update.addBlock(deindent`
|
|
|
|
var ${previous_block_index} = ${current_block_index};
|
|
|
|
var ${previous_block_index} = ${current_block_type_index};
|
|
|
|
${current_block_index} = ${get_block}( ${params} );
|
|
|
|
${current_block_type_index} = ${select_block_type}( ${params} );
|
|
|
|
if ( ${current_block_index} === ${previous_block_index} ) {
|
|
|
|
if ( ${current_block_type_index} === ${previous_block_index} ) {
|
|
|
|
${if_current_block_index}${if_blocks}[ ${current_block_index} ].update( changed, ${params} );
|
|
|
|
${if_current_block_type_index}${if_blocks}[ ${current_block_type_index} ].update( changed, ${params} );
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
${changeBlock}
|
|
|
|
${changeBlock}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
block.builders.update.addBlock(deindent`
|
|
|
|
block.builders.update.addBlock(deindent`
|
|
|
|
var ${previous_block_index} = ${current_block_index};
|
|
|
|
var ${previous_block_index} = ${current_block_type_index};
|
|
|
|
${current_block_index} = ${get_block}( ${params} );
|
|
|
|
${current_block_type_index} = ${select_block_type}( ${params} );
|
|
|
|
if ( ${current_block_index} !== ${previous_block_index} ) {
|
|
|
|
if ( ${current_block_type_index} !== ${previous_block_index} ) {
|
|
|
|
${changeBlock}
|
|
|
|
${changeBlock}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
block.builders.destroy.addLine(deindent`
|
|
|
|
block.builders.destroy.addLine(deindent`
|
|
|
|
${if_current_block_index}{
|
|
|
|
${if_current_block_type_index}{
|
|
|
|
${if_blocks}[ ${current_block_index} ].unmount();
|
|
|
|
${if_blocks}[ ${current_block_type_index} ].unmount();
|
|
|
|
${if_blocks}[ ${current_block_index} ].destroy();
|
|
|
|
${if_blocks}[ ${current_block_type_index} ].destroy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`);
|
|
|
|
`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|