Add hooks for HMR support (sveltejs#2377)

pull/3126/head
Axelen123 5 years ago
parent f06f718638
commit 838e8ab203
No known key found for this signature in database
GPG Key ID: 7B3388EF6070C533

@ -94,7 +94,7 @@ export default function dom(
const body = [];
const not_equal = component.component_options.immutable ? `@not_equal` : `@safe_not_equal`;
let dev_props_check;
let dev_props_check; let inject_state; let capture_state;
props.forEach(x => {
const variable = component.var_lookup.get(x.name);
@ -151,6 +151,21 @@ export default function dom(
}`)}
`;
}
capture_state = (uses_props || writable_props.length > 0) ? deindent`
() => {
return { ${component.vars.map(prop => prop.name).join(", ")} };
}
` : null;
inject_state = (uses_props || writable_props.length > 0) ? deindent`
${$$props} => {
${uses_props && component.invalidate('$$props', `$$props = @assign(@assign({}, $$props), $$new_props)`)}
${component.vars.map(prop => deindent`
if ('${prop.name}' in $$props) ${component.invalidate(prop.name, `${prop.name} = ${$$props}.${prop.name}`)};
`)}
}
` : null;
}
// instrument assignments
@ -430,6 +445,10 @@ export default function dom(
${set && `$$self.$set = ${set};`}
${capture_state && `$$self.$capture_state = ${capture_state};`}
${inject_state && `$$self.$inject_state = ${inject_state};`}
${injected.length && `let ${injected.join(', ')};`}
${reactive_declarations.length > 0 && deindent`

Loading…
Cancel
Save