update stores when assigning to store values - fixes #2170

pull/2250/head
Richard Harris 6 years ago
parent e87976dc21
commit 3e4dbc630f

@ -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})`;
}

@ -0,0 +1,32 @@
import { writable } from '../../../../store.js';
export default {
show: 1,
props: {
count: writable(0)
},
html: `
<button>count 0</button>
<p>doubled: 0</p>
`,
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, `
<button>count 1</button>
<p>doubled: 2</p>
`);
await component.count.set(42);
assert.htmlEqual(target.innerHTML, `
<button>count 42</button>
<p>doubled: 84</p>
`);
}
};

@ -0,0 +1,10 @@
<script>
import { derive } from 'svelte/store';
export let count;
const doubled = derive(count, $count => $count * 2);
</script>
<button on:click="{() => $count += 1}">count {$count}</button>
<p>doubled: {$doubled}</p>
Loading…
Cancel
Save