mirror of https://github.com/sveltejs/svelte
parent
d700bf1bc5
commit
484885d718
@ -0,0 +1,16 @@
|
||||
<script>
|
||||
let { a = $bindable() } = $props();
|
||||
|
||||
const bindings = $derived([
|
||||
() => a,
|
||||
(v) => {
|
||||
console.log('b', v);
|
||||
a = v;
|
||||
}
|
||||
]);
|
||||
</script>
|
||||
|
||||
<input
|
||||
type="value"
|
||||
bind:value={...bindings}
|
||||
/>
|
@ -0,0 +1,26 @@
|
||||
import { flushSync } from 'svelte';
|
||||
import { test } from '../../test';
|
||||
import { assert_ok } from '../../../suite';
|
||||
|
||||
export default test({
|
||||
async test({ assert, target, logs }) {
|
||||
const [input, checkbox] = target.querySelectorAll('input');
|
||||
|
||||
input.value = '2';
|
||||
input.dispatchEvent(new window.Event('input'));
|
||||
|
||||
flushSync();
|
||||
|
||||
assert.htmlEqual(
|
||||
target.innerHTML,
|
||||
`<button>a: 2</button><input type="value"><div><input type="checkbox" ></div>`
|
||||
);
|
||||
|
||||
assert.deepEqual(logs, ['b', '2', 'a', '2']);
|
||||
|
||||
flushSync(() => {
|
||||
checkbox.click();
|
||||
});
|
||||
assert.deepEqual(logs, ['b', '2', 'a', '2', 'check', false]);
|
||||
}
|
||||
});
|
@ -0,0 +1,30 @@
|
||||
<script>
|
||||
import Child from './Child.svelte';
|
||||
|
||||
let a = $state(0);
|
||||
const a_bindings = [
|
||||
() => a,
|
||||
(v) => {
|
||||
console.log('a', v);
|
||||
a = v;
|
||||
}
|
||||
]
|
||||
let check = $state(true);
|
||||
const check_bindings = [
|
||||
() => check,
|
||||
(v) => {
|
||||
console.log('check', v);
|
||||
check = v;
|
||||
}
|
||||
]
|
||||
</script>
|
||||
|
||||
<button onclick={() => a++}>a: {a}</button>
|
||||
|
||||
<Child
|
||||
bind:a={...a_bindings}
|
||||
/>
|
||||
|
||||
<div>
|
||||
<input type="checkbox" bind:checked={...check_bindings} />
|
||||
</div>
|
Loading…
Reference in new issue