From aaac15bafab2e2a4d53009385e187f727e195ab2 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Sun, 8 Sep 2019 20:55:30 -0400 Subject: [PATCH] remove $unsafe_set in favour of modified $inject_state --- src/compiler/compile/render_dom/index.ts | 24 ++++--------------- test/js/samples/debug-empty/expected.js | 4 ---- .../debug-foo-bar-baz-things/expected.js | 7 ------ test/js/samples/debug-foo/expected.js | 5 ---- test/js/samples/debug-hoisted/expected.js | 10 +++----- .../expected.js | 5 ---- 6 files changed, 8 insertions(+), 47 deletions(-) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index fe63c8e75c..504b5ffe05 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -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};`} diff --git a/test/js/samples/debug-empty/expected.js b/test/js/samples/debug-empty/expected.js index 851dbaaa4f..e0988b6222 100644 --- a/test/js/samples/debug-empty/expected.js +++ b/test/js/samples/debug-empty/expected.js @@ -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 }; }; diff --git a/test/js/samples/debug-foo-bar-baz-things/expected.js b/test/js/samples/debug-foo-bar-baz-things/expected.js index 3de09f7bf5..15d953f6bc 100644 --- a/test/js/samples/debug-foo-bar-baz-things/expected.js +++ b/test/js/samples/debug-foo-bar-baz-things/expected.js @@ -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 }; }; diff --git a/test/js/samples/debug-foo/expected.js b/test/js/samples/debug-foo/expected.js index 7e34482ded..08a92171d1 100644 --- a/test/js/samples/debug-foo/expected.js +++ b/test/js/samples/debug-foo/expected.js @@ -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 }; }; diff --git a/test/js/samples/debug-hoisted/expected.js b/test/js/samples/debug-hoisted/expected.js index 44a00bc702..62327860e2 100644 --- a/test/js/samples/debug-hoisted/expected.js +++ b/test/js/samples/debug-hoisted/expected.js @@ -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 }; diff --git a/test/js/samples/dev-warning-missing-data-computed/expected.js b/test/js/samples/dev-warning-missing-data-computed/expected.js index 079e771b64..ad0cbc8aba 100644 --- a/test/js/samples/dev-warning-missing-data-computed/expected.js +++ b/test/js/samples/dev-warning-missing-data-computed/expected.js @@ -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 }; };