capture store subscriptions in $capture_state

pull/3822/head
rixo 6 years ago
parent 002bed8f7b
commit eb4dcfcd5c

@ -165,24 +165,21 @@ export default function dom(
}
const capturable_vars = component.vars.filter(
variable => variable.writable && !(variable.injected || variable.name[0] === '$')
variable => variable.writable && (!variable.injected || variable.name[0] === '$')
);
if (uses_props || capturable_vars.length > 0) {
const injectable_vars = capturable_vars.filter(variable => variable.name[0] !== '$')
capture_state = x`() => ({ ${capturable_vars.map(prop => p`${prop.name}`)} }) `;
inject_state = x`
${$$props} => {
${(uses_props || injectable_vars.length > 0) && $$props} => {
${uses_props && renderer.invalidate('$$props', x`$$props = @assign(@assign({}, $$props), $$new_props)`)}
${capturable_vars.map(prop => b`
${injectable_vars.map(prop => b`
if ('${prop.name}' in $$props) ${renderer.invalidate(prop.name, x`${prop.name} = ${$$props}.${prop.name}`)};
`)}
}
`;
} else {
capture_state = x`() => ({})`;
inject_state = x`() => {}`;
}
}
// instrument assignments

@ -100,7 +100,7 @@ function instance($$self, $$props, $$invalidate) {
if ("alias" in $$props) $$invalidate(0, realName = $$props.alias);
};
$$self.$capture_state = () => ({ prop, realName, local });
$$self.$capture_state = () => ({ prop, realName, local, $prop });
$$self.$inject_state = $$props => {
if ("prop" in $$props) $$subscribe_prop($$invalidate(3, prop = $$props.prop));

Loading…
Cancel
Save