|
|
|
@ -78,7 +78,7 @@ class DomGenerator extends Generator {
|
|
|
|
|
} else {
|
|
|
|
|
properties.addBlock( deindent`
|
|
|
|
|
update: function ( changed, ${fragment.params.join( ', ' )} ) {
|
|
|
|
|
var __tmp;
|
|
|
|
|
${fragment.tmp ? `var ${fragment.tmp};` : ''}
|
|
|
|
|
|
|
|
|
|
${fragment.builders.update}
|
|
|
|
|
},
|
|
|
|
@ -119,8 +119,9 @@ class DomGenerator extends Generator {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
generateBlock ( node, name ) {
|
|
|
|
|
generateBlock ( node, name, type ) {
|
|
|
|
|
this.push({
|
|
|
|
|
type,
|
|
|
|
|
name,
|
|
|
|
|
target: 'target',
|
|
|
|
|
localElementDepth: 0,
|
|
|
|
@ -203,7 +204,8 @@ export default function dom ( parsed, source, options ) {
|
|
|
|
|
const component = getUniqueName( 'component' );
|
|
|
|
|
|
|
|
|
|
generator.push({
|
|
|
|
|
name: generator.alias( 'renderMainFragment' ),
|
|
|
|
|
type: 'block',
|
|
|
|
|
name: generator.alias( 'render_main_fragment' ),
|
|
|
|
|
namespace,
|
|
|
|
|
target: 'target',
|
|
|
|
|
localElementDepth: 0,
|
|
|
|
@ -241,7 +243,7 @@ export default function dom ( parsed, source, options ) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
builders._set.addLine( 'var oldState = this._state;' );
|
|
|
|
|
builders._set.addLine( 'this._state = Object.assign( {}, oldState, newState );' );
|
|
|
|
|
builders._set.addLine( `this._state = ${generator.helper( 'assign' )}( {}, oldState, newState );` );
|
|
|
|
|
|
|
|
|
|
if ( computations.length ) {
|
|
|
|
|
const builder = new CodeBuilder();
|
|
|
|
@ -277,13 +279,13 @@ export default function dom ( parsed, source, options ) {
|
|
|
|
|
|
|
|
|
|
if ( generator.css && options.css !== false ) {
|
|
|
|
|
builders.main.addBlock( deindent`
|
|
|
|
|
var ${generator.alias( 'addedCss' )} = false;
|
|
|
|
|
function ${generator.alias( 'addCss' )} () {
|
|
|
|
|
var ${generator.alias( 'added_css' )} = false;
|
|
|
|
|
function ${generator.alias( 'add_css' )} () {
|
|
|
|
|
var style = ${generator.helper( 'createElement' )}( 'style' );
|
|
|
|
|
style.textContent = ${JSON.stringify( generator.css )};
|
|
|
|
|
${generator.helper( 'appendNode' )}( style, document.head );
|
|
|
|
|
|
|
|
|
|
${generator.alias( 'addedCss' )} = true;
|
|
|
|
|
${generator.alias( 'added_css' )} = true;
|
|
|
|
|
}
|
|
|
|
|
` );
|
|
|
|
|
}
|
|
|
|
@ -294,7 +296,7 @@ export default function dom ( parsed, source, options ) {
|
|
|
|
|
builders.init.addLine( `this._torndown = false;` );
|
|
|
|
|
|
|
|
|
|
if ( parsed.css && options.css !== false ) {
|
|
|
|
|
builders.init.addLine( `if ( !${generator.alias( 'addedCss' )} ) ${generator.alias( 'addCss' )}();` );
|
|
|
|
|
builders.init.addLine( `if ( !${generator.alias( 'added_css' )} ) ${generator.alias( 'add_css' )}();` );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( generator.hasComponents ) {
|
|
|
|
@ -304,7 +306,7 @@ export default function dom ( parsed, source, options ) {
|
|
|
|
|
if ( generator.hasComplexBindings ) {
|
|
|
|
|
builders.init.addBlock( deindent`
|
|
|
|
|
this._bindings = [];
|
|
|
|
|
this._fragment = ${generator.alias( 'renderMainFragment' )}( this._state, this );
|
|
|
|
|
this._fragment = ${generator.alias( 'render_main_fragment' )}( this._state, this );
|
|
|
|
|
if ( options.target ) this._fragment.mount( options.target, null );
|
|
|
|
|
while ( this._bindings.length ) this._bindings.pop()();
|
|
|
|
|
` );
|
|
|
|
@ -312,7 +314,7 @@ export default function dom ( parsed, source, options ) {
|
|
|
|
|
builders._set.addLine( `while ( this._bindings.length ) this._bindings.pop()();` );
|
|
|
|
|
} else {
|
|
|
|
|
builders.init.addBlock( deindent`
|
|
|
|
|
this._fragment = ${generator.alias( 'renderMainFragment' )}( this._state, this );
|
|
|
|
|
this._fragment = ${generator.alias( 'render_main_fragment' )}( this._state, this );
|
|
|
|
|
if ( options.target ) this._fragment.mount( options.target, null );
|
|
|
|
|
` );
|
|
|
|
|
}
|
|
|
|
@ -340,7 +342,7 @@ export default function dom ( parsed, source, options ) {
|
|
|
|
|
if ( generator.usesRefs ) constructorBlock.addLine( `this.refs = {};` );
|
|
|
|
|
|
|
|
|
|
constructorBlock.addLine(
|
|
|
|
|
`this._state = ${templateProperties.data ? `Object.assign( ${generator.alias( 'template' )}.data(), options.data )` : `options.data || {}`};`
|
|
|
|
|
`this._state = ${templateProperties.data ? `${generator.helper( 'assign' )}( ${generator.alias( 'template' )}.data(), options.data )` : `options.data || {}`};`
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if ( !generator.builders.metaBindings.isEmpty() ) {
|
|
|
|
@ -393,7 +395,7 @@ export default function dom ( parsed, source, options ) {
|
|
|
|
|
|
|
|
|
|
if ( sharedPath ) {
|
|
|
|
|
const base = templateProperties.methods ? `{}, ${generator.alias( 'template' )}.methods` : `{}`;
|
|
|
|
|
builders.main.addBlock( `${name}.prototype = Object.assign( ${base}, ${generator.helper( 'proto' )} );` );
|
|
|
|
|
builders.main.addBlock( `${name}.prototype = ${generator.helper( 'assign' )}( ${base}, ${generator.helper( 'proto' )} );` );
|
|
|
|
|
} else {
|
|
|
|
|
if ( templateProperties.methods ) {
|
|
|
|
|
builders.main.addBlock( `${name}.prototype = ${generator.alias( 'template' )}.methods;` );
|
|
|
|
|