mirror of https://github.com/sveltejs/svelte
Merge pull request #2265 from sveltejs/gh-2119
Handle store assignments in reactive statementspull/2269/head
commit
f6aed0810b
@ -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