fix #301, even with non-primitive values

pull/304/head
Rich Harris 9 years ago
parent b67ef91b66
commit 2cb4ca2c8d

@ -10,7 +10,7 @@ export default {
return Component.enter( generator, node );
}
const name = node.localName = generator.current.getUniqueName( node.name );
const name = generator.current.getUniqueName( node.name );
const local = {
name,
@ -111,8 +111,12 @@ export default {
return Component.leave( generator, node );
}
if ( generator.current.initialUpdate ) {
generator.current.builders.init.addBlock( generator.current.initialUpdate );
if ( node.initialUpdate ) {
console.log( `node.initialUpdate`, node.initialUpdate )
//generator.current.builders.init.addBlock( node.initialUpdate );
generator.current.builders.init.addBlock(
`/*HELLO*/` + node.initialUpdate
);
}
generator.pop();

@ -116,7 +116,27 @@ export default function createBinding ( generator, node, attribute, current, loc
}
` );
} else {
const updateElement = `${local.name}.${attribute.name} = ${contextual ? attribute.value : `root.${attribute.value}`};`;
let updateElement;
if ( node.name === 'select' ) {
// TODO select multiple
const value = generator.current.getUniqueName( 'value' );
const i = generator.current.getUniqueName( 'i' );
const option = generator.current.getUniqueName( 'option' );
updateElement = deindent`
var ${value} = ${contextual ? attribute.value : `root.${attribute.value}`};
for ( var ${i} = 0; ${i} < ${local.name}.options.length; ${i} += 1 ) {
var ${option} = ${local.name}.options[${i}];
if ( ${option}.__value === ${value} ) {
${option}.selected = true;
break;
}
}
`;
} else {
updateElement = `${local.name}.${attribute.name} = ${contextual ? attribute.value : `root.${attribute.value}`};`;
}
generator.uses.addEventListener = true;
generator.uses.removeEventListener = true;
@ -132,7 +152,7 @@ export default function createBinding ( generator, node, attribute, current, loc
addEventListener( ${local.name}, '${eventName}', ${handler} );
` );
generator.current.initialUpdate = updateElement;
node.initialUpdate = updateElement;
local.update.addLine(
`if ( !${local.name}_updating ) ${updateElement}`

Loading…
Cancel
Save