|
|
@ -86,7 +86,9 @@ export default function dom(
|
|
|
|
`( '${dep}' in newState && @differs( state.${dep}, oldState.${dep} ) )`
|
|
|
|
`( '${dep}' in newState && @differs( state.${dep}, oldState.${dep} ) )`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.join(' || ')}`;
|
|
|
|
.join(' || ')}`;
|
|
|
|
const statement = `state.${key} = newState.${key} = @template.computed.${key}( ${deps.map(dep => `state.${dep}`).join(', ')} );`;
|
|
|
|
const statement = `state.${key} = newState.${key} = @template.computed.${key}( ${deps
|
|
|
|
|
|
|
|
.map(dep => `state.${dep}`)
|
|
|
|
|
|
|
|
.join(', ')} );`;
|
|
|
|
|
|
|
|
|
|
|
|
computationBuilder.addConditionalLine(condition, statement);
|
|
|
|
computationBuilder.addConditionalLine(condition, statement);
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -113,7 +115,8 @@ export default function dom(
|
|
|
|
|
|
|
|
|
|
|
|
var oldState = this._state;
|
|
|
|
var oldState = this._state;
|
|
|
|
this._state = @assign( {}, oldState, newState );
|
|
|
|
this._state = @assign( {}, oldState, newState );
|
|
|
|
${computations.length && `@recompute( this._state, newState, oldState, false )`}
|
|
|
|
${computations.length &&
|
|
|
|
|
|
|
|
`@recompute( this._state, newState, oldState, false )`}
|
|
|
|
@dispatchObservers( this, this._observers.pre, newState, oldState );
|
|
|
|
@dispatchObservers( this, this._observers.pre, newState, oldState );
|
|
|
|
${block.hasUpdateMethod && `this._fragment.update( newState, this._state );`}
|
|
|
|
${block.hasUpdateMethod && `this._fragment.update( newState, this._state );`}
|
|
|
|
@dispatchObservers( this, this._observers.post, newState, oldState );
|
|
|
|
@dispatchObservers( this, this._observers.post, newState, oldState );
|
|
|
@ -124,9 +127,7 @@ export default function dom(
|
|
|
|
`;
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
|
|
if (hasJs) {
|
|
|
|
if (hasJs) {
|
|
|
|
builder.addBlock(
|
|
|
|
builder.addBlock(`[✂${parsed.js.content.start}-${parsed.js.content.end}✂]`);
|
|
|
|
`[✂${parsed.js.content.start}-${parsed.js.content.end}✂]`
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (generator.css && options.css !== false) {
|
|
|
|
if (generator.css && options.css !== false) {
|
|
|
@ -150,9 +151,7 @@ export default function dom(
|
|
|
|
|
|
|
|
|
|
|
|
const prototypeBase =
|
|
|
|
const prototypeBase =
|
|
|
|
`${name}.prototype` +
|
|
|
|
`${name}.prototype` +
|
|
|
|
(templateProperties.methods
|
|
|
|
(templateProperties.methods ? `, @template.methods` : '');
|
|
|
|
? `, @template.methods`
|
|
|
|
|
|
|
|
: '');
|
|
|
|
|
|
|
|
const proto = sharedPath
|
|
|
|
const proto = sharedPath
|
|
|
|
? `@proto `
|
|
|
|
? `@proto `
|
|
|
|
: deindent`
|
|
|
|
: deindent`
|
|
|
@ -173,8 +172,7 @@ export default function dom(
|
|
|
|
? `@assign( @template.data(), options.data )`
|
|
|
|
? `@assign( @template.data(), options.data )`
|
|
|
|
: `options.data || {}`};
|
|
|
|
: `options.data || {}`};
|
|
|
|
${generator.metaBindings}
|
|
|
|
${generator.metaBindings}
|
|
|
|
${computations.length &&
|
|
|
|
${computations.length && `@recompute( this._state, this._state, {}, true );`}
|
|
|
|
`@recompute( this._state, this._state, {}, true );`}
|
|
|
|
|
|
|
|
${options.dev &&
|
|
|
|
${options.dev &&
|
|
|
|
Array.from(generator.expectedProperties).map(
|
|
|
|
Array.from(generator.expectedProperties).map(
|
|
|
|
prop =>
|
|
|
|
prop =>
|
|
|
@ -206,13 +204,13 @@ export default function dom(
|
|
|
|
this._fragment = @create_main_fragment( this._state, this );
|
|
|
|
this._fragment = @create_main_fragment( this._state, this );
|
|
|
|
|
|
|
|
|
|
|
|
if ( options.target ) {
|
|
|
|
if ( options.target ) {
|
|
|
|
${generator.hydratable ?
|
|
|
|
${generator.hydratable
|
|
|
|
deindent`
|
|
|
|
? deindent`
|
|
|
|
var nodes = @children( options.target );
|
|
|
|
var nodes = @children( options.target );
|
|
|
|
options.hydrate ? this._fragment.claim( nodes ) : this._fragment.create();
|
|
|
|
options.hydrate ? this._fragment.claim( nodes ) : this._fragment.create();
|
|
|
|
nodes.forEach( @detachNode );
|
|
|
|
nodes.forEach( @detachNode );
|
|
|
|
` :
|
|
|
|
`
|
|
|
|
deindent`
|
|
|
|
: deindent`
|
|
|
|
this._fragment.create();
|
|
|
|
this._fragment.create();
|
|
|
|
`}
|
|
|
|
`}
|
|
|
|
this._fragment.mount( options.target, null );
|
|
|
|
this._fragment.mount( options.target, null );
|
|
|
@ -241,8 +239,7 @@ export default function dom(
|
|
|
|
|
|
|
|
|
|
|
|
${name}.prototype.teardown = ${name}.prototype.destroy = function destroy ( detach ) {
|
|
|
|
${name}.prototype.teardown = ${name}.prototype.destroy = function destroy ( detach ) {
|
|
|
|
this.fire( 'destroy' );
|
|
|
|
this.fire( 'destroy' );
|
|
|
|
${templateProperties.ondestroy &&
|
|
|
|
${templateProperties.ondestroy && `@template.ondestroy.call( this );`}
|
|
|
|
`@template.ondestroy.call( this );`}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( detach !== false ) this._fragment.unmount();
|
|
|
|
if ( detach !== false ) this._fragment.unmount();
|
|
|
|
this._fragment.destroy();
|
|
|
|
this._fragment.destroy();
|
|
|
@ -255,7 +252,8 @@ export default function dom(
|
|
|
|
|
|
|
|
|
|
|
|
const usedHelpers = new Set();
|
|
|
|
const usedHelpers = new Set();
|
|
|
|
|
|
|
|
|
|
|
|
let result = builder.toString()
|
|
|
|
let result = builder
|
|
|
|
|
|
|
|
.toString()
|
|
|
|
.replace(/@(\w+)\b/g, (match: string, name: string) => {
|
|
|
|
.replace(/@(\w+)\b/g, (match: string, name: string) => {
|
|
|
|
if (name in shared) {
|
|
|
|
if (name in shared) {
|
|
|
|
if (options.dev && `${name}Dev` in shared) name = `${name}Dev`;
|
|
|
|
if (options.dev && `${name}Dev` in shared) name = `${name}Dev`;
|
|
|
@ -277,7 +275,9 @@ export default function dom(
|
|
|
|
: name;
|
|
|
|
: name;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
result = `import { ${names.join(', ')} } from ${stringify(sharedPath)};\n\n` + result;
|
|
|
|
result =
|
|
|
|
|
|
|
|
`import { ${names.join(', ')} } from ${stringify(sharedPath)};\n\n` +
|
|
|
|
|
|
|
|
result;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
usedHelpers.forEach(key => {
|
|
|
|
usedHelpers.forEach(key => {
|
|
|
|
const str = shared[key];
|
|
|
|
const str = shared[key];
|
|
|
|