remove $unsafe_set in favour of modified $inject_state

pull/3005/head
Richard Harris 6 years ago
parent 8174119746
commit f2568f6665

@ -74,7 +74,6 @@ export default function dom(
const $$props = uses_props ? `$$new_props` : `$$props`;
const props = component.vars.filter(variable => !variable.module && variable.export_name);
const writable_props = props.filter(variable => variable.writable);
const writable_vars = component.vars.filter(variable => !variable.module && variable.writable);
/* eslint-disable @typescript-eslint/indent,indent */
const set = (uses_props || writable_props.length > 0 || component.slots.size > 0)
@ -89,16 +88,6 @@ export default function dom(
}
`
: null;
const unsafe_set = writable_vars.length > 0
? deindent`
$$values => {
${writable_vars.map(variable =>
`if ('${variable.name}' in $$values) ${component.invalidate(variable.name, `${variable.name} = $$values.${variable.name}`)};`
)}
}
`
: null;
/* eslint-enable @typescript-eslint/indent,indent */
const body = [];
@ -168,21 +157,20 @@ export default function dom(
}
` : deindent`
() => {
return {}
return {};
}
`;
inject_state = (uses_props || writable_props.length > 0) ? deindent`
const writable_vars = component.vars.filter(variable => !variable.module && variable.writable);
inject_state = (uses_props || writable_vars.length > 0) ? deindent`
${$$props} => {
${uses_props && component.invalidate('$$props', `$$props = @assign(@assign({}, $$props), $$new_props)`)}
${component.vars.filter(prop => prop.writable).map(prop => deindent`
${writable_vars.map(prop => deindent`
if ('${prop.name}' in $$props) ${component.invalidate(prop.name, `${prop.name} = ${$$props}.${prop.name}`)};
`)}
}
` : deindent`
${$$props} => {
return
}
${$$props} => {}
`;
}
@ -385,8 +373,6 @@ export default function dom(
${set && `$$self.$set = ${set};`}
${unsafe_set && component.compile_options.dev && `$$self.$unsafe_set = ${unsafe_set};`}
${capture_state && `$$self.$capture_state = ${capture_state};`}
${inject_state && `$$self.$inject_state = ${inject_state};`}

@ -77,10 +77,6 @@ function instance($$self, $$props, $$invalidate) {
if ('name' in $$props) $$invalidate('name', name = $$props.name);
};
$$self.$unsafe_set = $$values => {
if ('name' in $$values) $$invalidate('name', name = $$values.name);
};
$$self.$capture_state = () => {
return { name };
};

@ -169,13 +169,6 @@ function instance($$self, $$props, $$invalidate) {
if ('baz' in $$props) $$invalidate('baz', baz = $$props.baz);
};
$$self.$unsafe_set = $$values => {
if ('things' in $$values) $$invalidate('things', things = $$values.things);
if ('foo' in $$values) $$invalidate('foo', foo = $$values.foo);
if ('bar' in $$values) $$invalidate('bar', bar = $$values.bar);
if ('baz' in $$values) $$invalidate('baz', baz = $$values.baz);
};
$$self.$capture_state = () => {
return { things, foo, bar, baz };
};

@ -167,11 +167,6 @@ function instance($$self, $$props, $$invalidate) {
if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo);
};
$$self.$unsafe_set = $$values => {
if ('things' in $$values) $$invalidate('things', things = $$values.things);
if ('foo' in $$values) $$invalidate('foo', foo = $$values.foo);
};
$$self.$capture_state = () => {
return { things, foo };
};

@ -46,17 +46,13 @@ let kobzol = 5;
function instance($$self) {
let obj = { x: 5 };
$$self.$unsafe_set = $$values => {
if ('obj' in $$values) $$invalidate('obj', obj = $$values.obj);
if ('kobzol' in $$values) $$invalidate('kobzol', kobzol = $$values.kobzol);
};
$$self.$capture_state = () => {
return {}
return {};
};
$$self.$inject_state = $$props => {
return
if ('obj' in $$props) $$invalidate('obj', obj = $$props.obj);
if ('kobzol' in $$props) $$invalidate('kobzol', kobzol = $$props.kobzol);
};
return { obj };

@ -77,11 +77,6 @@ function instance($$self, $$props, $$invalidate) {
if ('foo' in $$props) $$invalidate('foo', foo = $$props.foo);
};
$$self.$unsafe_set = $$values => {
if ('foo' in $$values) $$invalidate('foo', foo = $$values.foo);
if ('bar' in $$values) $$invalidate('bar', bar = $$values.bar);
};
$$self.$capture_state = () => {
return { foo, bar };
};

Loading…
Cancel
Save