mirror of https://github.com/sveltejs/svelte
Merge pull request #2250 from sveltejs/gh-2170
update stores when assigning to store valuespull/2258/head
commit
1e3666f86f
@ -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…
Reference in new issue