mirror of https://github.com/sveltejs/svelte
parent
1a0b822f48
commit
3e222fca39
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': minor
|
||||
---
|
||||
|
||||
feat: add $state.opqaue rune
|
@ -0,0 +1,38 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
import { assert_ok } from '../../../suite';
|
||||
|
||||
export default test({
|
||||
html: `<button>+</button><button>invalidate</button><div>0</div><div>0</div><input>`,
|
||||
ssrHtml: `<button>+</button><button>invalidate</button><div>0</div><div>0</div><input value="0">`,
|
||||
|
||||
test({ assert, target }) {
|
||||
const [b1, b2] = target.querySelectorAll('button');
|
||||
const input = target.querySelector('input');
|
||||
assert_ok(input);
|
||||
|
||||
b1?.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>+</button><button>invalidate</button><div>0</div><div>0</div><input>`
|
||||
);
|
||||
assert.equal(input.value, '0');
|
||||
|
||||
b2?.click();
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>+</button><button>invalidate</button><div>1</div><div>1</div><input>`
|
||||
);
|
||||
assert.equal(input.value, '1');
|
||||
|
||||
input.value = '2';
|
||||
input.dispatchEvent(new window.Event('input'));
|
||||
flushSync();
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>+</button><button>invalidate</button><div>1</div><div>1</div><input>`
|
||||
);
|
||||
}
|
||||
});
|
@ -0,0 +1,19 @@
|
||||
<script>
|
||||
let [count, invalidate_count] = $state.opaque(0);
|
||||
let [value, invalidate_value] = $state.opaque({ count: 0 });
|
||||
</script>
|
||||
|
||||
<button onclick={() => {
|
||||
count++
|
||||
value.count++
|
||||
}}>+</button>
|
||||
|
||||
<button onclick={() => {
|
||||
invalidate_count();
|
||||
invalidate_value();
|
||||
}}>invalidate</button>
|
||||
|
||||
<div>{count}</div>
|
||||
<div>{value.count}</div>
|
||||
|
||||
<input bind:value={count}>
|
Loading…
Reference in new issue