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