mirror of https://github.com/sveltejs/svelte
commit
0fd4d2adcc
@ -1,8 +0,0 @@
|
|||||||
import { test } from '../../test';
|
|
||||||
|
|
||||||
export default test({
|
|
||||||
error: {
|
|
||||||
code: 'constant_assignment',
|
|
||||||
message: 'Cannot assign to derived state'
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,5 +0,0 @@
|
|||||||
<script>
|
|
||||||
const a = $state(0);
|
|
||||||
let b = $derived(a);
|
|
||||||
b = 1;
|
|
||||||
</script>
|
|
@ -1,8 +0,0 @@
|
|||||||
import { test } from '../../test';
|
|
||||||
|
|
||||||
export default test({
|
|
||||||
error: {
|
|
||||||
code: 'constant_binding',
|
|
||||||
message: 'Cannot bind to derived state'
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,6 +0,0 @@
|
|||||||
<script>
|
|
||||||
let a = $state(0);
|
|
||||||
let b = $derived({ a });
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<input type="number" bind:value={b} />
|
|
@ -1,8 +0,0 @@
|
|||||||
import { test } from '../../test';
|
|
||||||
|
|
||||||
export default test({
|
|
||||||
error: {
|
|
||||||
code: 'constant_assignment',
|
|
||||||
message: 'Cannot assign to derived state'
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,10 +0,0 @@
|
|||||||
<script>
|
|
||||||
class Counter {
|
|
||||||
count = $state();
|
|
||||||
#doubled = $derived(this.count * 2);
|
|
||||||
|
|
||||||
nope() {
|
|
||||||
this.#doubled += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -1,8 +0,0 @@
|
|||||||
import { test } from '../../test';
|
|
||||||
|
|
||||||
export default test({
|
|
||||||
error: {
|
|
||||||
code: 'constant_assignment',
|
|
||||||
message: 'Cannot assign to derived state'
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,10 +0,0 @@
|
|||||||
<script>
|
|
||||||
class Counter {
|
|
||||||
count = $state();
|
|
||||||
#doubled = $derived(this.count * 2);
|
|
||||||
|
|
||||||
nope() {
|
|
||||||
this.#doubled++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -1,8 +0,0 @@
|
|||||||
import { test } from '../../test';
|
|
||||||
|
|
||||||
export default test({
|
|
||||||
error: {
|
|
||||||
code: 'constant_assignment',
|
|
||||||
message: 'Cannot assign to derived state'
|
|
||||||
}
|
|
||||||
});
|
|
@ -1,5 +0,0 @@
|
|||||||
<script>
|
|
||||||
const a = $state(0);
|
|
||||||
let b = $derived(a);
|
|
||||||
b++;
|
|
||||||
</script>
|
|
@ -0,0 +1,5 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `<p>state,derived state,derived.by derived state</p>`
|
||||||
|
});
|
@ -0,0 +1,18 @@
|
|||||||
|
<script>
|
||||||
|
class Foo {
|
||||||
|
#state = $state('state')
|
||||||
|
#derived = $derived('derived ' + this.#state);
|
||||||
|
#derivedBy = $derived.by(() => {
|
||||||
|
return 'derived.by ' + this.#derived
|
||||||
|
});
|
||||||
|
|
||||||
|
initial
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
this.initial = [this.#state, this.#derived, this.#derivedBy]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const foo = new Foo()
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<p>{foo.initial}</p>
|
@ -0,0 +1,16 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target }) {
|
||||||
|
let btn = target.querySelector('button');
|
||||||
|
|
||||||
|
btn?.click();
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<div>Count 1!</div><div>Count from store 1!</div><button>Add 1</button>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,11 @@
|
|||||||
|
<script>
|
||||||
|
import { toStore } from "svelte/store";
|
||||||
|
|
||||||
|
let counter = $state(0);
|
||||||
|
const count = toStore(() => counter, value => counter = value);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div>Count {counter}!</div>
|
||||||
|
<div>Count from store {$count}!</div>
|
||||||
|
|
||||||
|
<button onclick={() => counter+=1}>Add 1</button>
|
@ -0,0 +1,46 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `
|
||||||
|
<input type="range"><input type="range"><p>0 * 2 = 0</p>
|
||||||
|
`,
|
||||||
|
|
||||||
|
ssrHtml: `
|
||||||
|
<input type="range" value="0"><input type="range" value="0"><p>0 * 2 = 0</p>
|
||||||
|
`,
|
||||||
|
|
||||||
|
test({ assert, target, window }) {
|
||||||
|
const [input1, input2] = target.querySelectorAll('input');
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
input1.value = '10';
|
||||||
|
input1.dispatchEvent(new window.Event('input', { bubbles: true }));
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<input type="range"><input type="range"><p>10 * 2 = 20</p>`
|
||||||
|
);
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
input2.value = '99';
|
||||||
|
input2.dispatchEvent(new window.Event('input', { bubbles: true }));
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<input type="range"><input type="range"><p>10 * 2 = 99</p>`
|
||||||
|
);
|
||||||
|
|
||||||
|
flushSync(() => {
|
||||||
|
input1.value = '20';
|
||||||
|
input1.dispatchEvent(new window.Event('input', { bubbles: true }));
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<input type="range"><input type="range"><p>20 * 2 = 40</p>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
let count = $state(0);
|
||||||
|
let double = $derived(count * 2);
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<input type="range" bind:value={count} />
|
||||||
|
<input type="range" bind:value={double} />
|
||||||
|
|
||||||
|
<p>{count} * 2 = {double}</p>
|
@ -1,14 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"code": "constant_assignment",
|
|
||||||
"message": "Cannot assign to derived state",
|
|
||||||
"start": {
|
|
||||||
"column": 3,
|
|
||||||
"line": 6
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"column": 29,
|
|
||||||
"line": 6
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
@ -1,9 +0,0 @@
|
|||||||
<script>
|
|
||||||
class Test{
|
|
||||||
der = $derived({ test: 0 });
|
|
||||||
|
|
||||||
set test(v){
|
|
||||||
this["der"] = { test: 45 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -1,14 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"code": "constant_assignment",
|
|
||||||
"message": "Cannot assign to derived state",
|
|
||||||
"start": {
|
|
||||||
"column": 3,
|
|
||||||
"line": 6
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"column": 27,
|
|
||||||
"line": 6
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
@ -1,9 +0,0 @@
|
|||||||
<script>
|
|
||||||
class Test{
|
|
||||||
#der = $derived({ test: 0 });
|
|
||||||
|
|
||||||
set test(v){
|
|
||||||
this.#der = { test: 45 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
@ -1,14 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"code": "constant_assignment",
|
|
||||||
"message": "Cannot assign to derived state",
|
|
||||||
"start": {
|
|
||||||
"column": 3,
|
|
||||||
"line": 6
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"column": 26,
|
|
||||||
"line": 6
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
@ -1,9 +0,0 @@
|
|||||||
<script>
|
|
||||||
class Test{
|
|
||||||
der = $derived({ test: 0 });
|
|
||||||
|
|
||||||
set test(v){
|
|
||||||
this.der = { test: 45 };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
Loading…
Reference in new issue