only inject props and refs if necessary

pull/1864/head
Rich Harris 7 years ago
parent 8ff75d7632
commit 5d267f7121

@ -123,6 +123,25 @@ export default function dom(
options.css !== false options.css !== false
); );
const props = component.exports.filter(x => component.writable_declarations.has(x.name));
const inject_props = props.length > 0
? deindent`
props => {
${props.map(prop =>
`if ('${prop.as}' in props) ${prop.name} = props.${prop.as};`)}
}
`
: `@noop`;
const inject_refs = refs.length > 0
? deindent`
refs => {
${refs.map(name => `${name} = refs.${name};`)}
}
`
: `@noop`;
const body = [ const body = [
deindent` deindent`
$$init($$make_dirty) { $$init($$make_dirty) {
@ -138,16 +157,8 @@ export default function dom(
return [ return [
// TODO only what's needed by the template // TODO only what's needed by the template
() => ({ ${component.declarations.join(', ')} }), () => ({ ${component.declarations.join(', ')} }),
props => { ${inject_props},
// TODO only do this for export let|var ${inject_refs}
${(component.exports.map(name =>
`if ('${name.as}' in props) ${name.as} = props.${name.as};`
))}
},
refs => {
// TODO only if we have some refs
${refs.map(name => `${name} = refs.${name};`)}
}
]; ];
} }

Loading…
Cancel
Save