From 126c515d22c05377f5ecad85ba44efcb2f88b247 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Sun, 9 Jun 2019 14:11:21 -0700 Subject: [PATCH] Component.$unsafe_set --- src/compiler/compile/render_dom/index.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/compiler/compile/render_dom/index.ts b/src/compiler/compile/render_dom/index.ts index c1c2ebae56..b41b4c2f08 100644 --- a/src/compiler/compile/render_dom/index.ts +++ b/src/compiler/compile/render_dom/index.ts @@ -75,6 +75,7 @@ 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,6 +90,16 @@ 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 = []; @@ -430,6 +441,8 @@ export default function dom( ${set && `$$self.$set = ${set};`} + ${unsafe_set && component.compile_options.dev && `$$self.$unsafe_set = ${unsafe_set};`} + ${injected.length && `let ${injected.join(', ')};`} ${reactive_declarations.length > 0 && deindent`