diff --git a/src/compile/Component.ts b/src/compile/Component.ts index 4e0fcdb1c9..02e1712280 100644 --- a/src/compile/Component.ts +++ b/src/compile/Component.ts @@ -719,9 +719,15 @@ export default class Component { invalidate(name, value = name) { const variable = this.var_lookup.get(name); + if (variable && (variable.subscribable && variable.reassigned)) { return `$$subscribe_${name}(), $$invalidate('${name}', ${value})`; } + + if (name[0] === '$' && name[1] !== '$') { + return `${name.slice(1)}.set(${name})` + } + return `$$invalidate('${name}', ${value})`; } diff --git a/test/runtime/samples/store-assignment-updates/_config.js b/test/runtime/samples/store-assignment-updates/_config.js new file mode 100644 index 0000000000..74cff8b4d5 --- /dev/null +++ b/test/runtime/samples/store-assignment-updates/_config.js @@ -0,0 +1,32 @@ +import { writable } from '../../../../store.js'; + +export default { + show: 1, + props: { + count: writable(0) + }, + + html: ` + +

doubled: 0

+ `, + + async test({ assert, component, target, window }) { + const button = target.querySelector('button'); + const click = new window.MouseEvent('click'); + + await button.dispatchEvent(click); + + assert.htmlEqual(target.innerHTML, ` + +

doubled: 2

+ `); + + await component.count.set(42); + + assert.htmlEqual(target.innerHTML, ` + +

doubled: 84

+ `); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/store-assignment-updates/main.svelte b/test/runtime/samples/store-assignment-updates/main.svelte new file mode 100644 index 0000000000..fcce04dd36 --- /dev/null +++ b/test/runtime/samples/store-assignment-updates/main.svelte @@ -0,0 +1,10 @@ + + + +

doubled: {$doubled}

\ No newline at end of file