reverse bad fix from yesterday - only have state object in mount if its a yield block

pull/725/head
Rich Harris 7 years ago
parent ab607269f9
commit fc7e104e63

@ -317,7 +317,9 @@ const preprocessors = {
generator.components.has(node.name) || node.name === ':Self';
if (isComponent) {
node._state = getChildState(state);
node._state = getChildState(state, {
isYield: true
});
} else {
const name = block.getUniqueName(
node.name.replace(/[^a-zA-Z0-9_$]/g, '_')

@ -87,16 +87,8 @@ export default function visitBinding(
const { name } = getObject(attribute.value);
const tailSnippet = getTailSnippet(attribute.value);
if (state.inEachBlock === true) {
updateElement = deindent`
var ${value} = ${snippet};
`;
} else {
updateElement = deindent`
var ${value} = #component.get( '${name}' )${tailSnippet};
`;
}
updateElement += `
updateElement = deindent`
var ${value} = ${snippet};
for ( var #i = 0; #i < ${state.parentNode}.options.length; #i += 1 ) {
var ${option} = ${state.parentNode}.options[#i];
@ -168,8 +160,10 @@ export default function visitBinding(
`@addListener( ${state.parentNode}, '${eventName}', ${handler} );`
);
if (node.name !== 'audio' && node.name !== 'video')
if (node.name !== 'audio' && node.name !== 'video') {
node.initialUpdate = updateElement;
node.initialUpdateNeedsStateObject = !block.contexts.has(name);
}
if (updateCondition !== null) {
// audio/video duration is read-only, it never updates

@ -195,6 +195,17 @@ export default function visitElement(
}
if (node.initialUpdate) {
// special case — if we're in a yield block, then we may call mount
// long after the fragment is created. We may therefore need to get
// the latest `state` object
// TODO what about contexts in yield blocks? do we need to do
// `var ${contextName} = [something complicated]`?
const needsStateObject = node.initialUpdateNeedsStateObject && state.isYield;
if ( needsStateObject ) {
block.builders.mount.addLine(`var state = #component.get()`);
}
block.builders.mount.addBlock(node.initialUpdate);
}

Loading…
Cancel
Save