wait this is actually way easier

pull/488/head
Rich-Harris 8 years ago
parent 227ce7928c
commit 7a3611b5df

@ -1,6 +1,6 @@
import deindent from '../../../../utils/deindent.js';
import flattenReference from '../../../../utils/flattenReference.js';
import getSetter, { getTailSnippet } from '../shared/binding/getSetter.js';
import getSetter from '../shared/binding/getSetter.js';
export default function visitBinding ( generator, block, state, node, attribute, local ) {
const { name, keypath } = flattenReference( attribute.value );
@ -41,8 +41,6 @@ export default function visitBinding ( generator, block, state, node, attribute,
const updating = block.getUniqueName( `${local.name}_updating` );
const initialValue = getInitialValue({ block, local, attribute, name });
local.create.addBlock( deindent`
var ${updating} = false;
@ -53,7 +51,7 @@ export default function visitBinding ( generator, block, state, node, attribute,
${updating} = true;
${setter}
${updating} = false;
}, { init: ${generator.helper( 'differs' )}( ${local.name}.get( '${attribute.name}' ), ${initialValue} ) });
}, { init: ${generator.helper( 'differs' )}( ${local.name}.get( '${attribute.name}' ), ${snippet} ) });
});
` );
@ -65,18 +63,3 @@ export default function visitBinding ( generator, block, state, node, attribute,
}
` );
}
function getInitialValue ({ block, local, attribute, name }) {
const tail = attribute.value.type === 'MemberExpression' ? getTailSnippet( attribute.value ) : '';
if ( block.contexts.has( name ) ) {
// const prop = dependencies[0];
const list = `${local.name}._context.${block.listNames.get( name )}`;
const index = `${local.name}._context.${block.indexNames.get( name )}`;
return `${list}[${index}]${tail}`;
}
return `${block.component}.get( '${name}' )${tail}`;
}

@ -25,7 +25,7 @@ export default function getSetter ({ block, name, keypath, context, attribute, d
return `${block.component}._set({ ${name}: ${value} });`;
}
export function getTailSnippet ( node ) {
function getTailSnippet ( node ) {
const end = node.end;
while ( node.type === 'MemberExpression' ) node = node.object;
const start = node.end;

Loading…
Cancel
Save