mirror of https://github.com/sveltejs/svelte
handle assignments to store values in reactive declarations (#2119)
parent
51ab376de8
commit
9955ac13ac
@ -0,0 +1,42 @@
|
|||||||
|
import { writable } from '../../../../store.js';
|
||||||
|
|
||||||
|
const c = writable(0);
|
||||||
|
|
||||||
|
export default {
|
||||||
|
props: {
|
||||||
|
c
|
||||||
|
},
|
||||||
|
|
||||||
|
html: `
|
||||||
|
<p>a: 0</p>
|
||||||
|
<p>b: 0</p>
|
||||||
|
<p>c: 0</p>
|
||||||
|
|
||||||
|
<button>+1</button>
|
||||||
|
`,
|
||||||
|
|
||||||
|
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, `
|
||||||
|
<p>a: 1</p>
|
||||||
|
<p>b: 1</p>
|
||||||
|
<p>c: 1</p>
|
||||||
|
|
||||||
|
<button>+1</button>
|
||||||
|
`);
|
||||||
|
|
||||||
|
await component.c.set(42);
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, `
|
||||||
|
<p>a: 42</p>
|
||||||
|
<p>b: 42</p>
|
||||||
|
<p>c: 42</p>
|
||||||
|
|
||||||
|
<button>+1</button>
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,20 @@
|
|||||||
|
<script>
|
||||||
|
import { writable } from '../../../../store.js';
|
||||||
|
|
||||||
|
const a = writable();
|
||||||
|
const b = writable();
|
||||||
|
export let c;
|
||||||
|
|
||||||
|
$: $a = $b;
|
||||||
|
$: $b = $c;
|
||||||
|
|
||||||
|
function increment() {
|
||||||
|
$c += 1;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>a: {$a}</p>
|
||||||
|
<p>b: {$b}</p>
|
||||||
|
<p>c: {$c}</p>
|
||||||
|
|
||||||
|
<button on:click={increment}>+1</button>
|
Loading…
Reference in new issue