mirror of https://github.com/sveltejs/svelte
parent
76ce303b0a
commit
b3eeee08b6
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: thunkify deriveds on the server
|
@ -0,0 +1,5 @@
|
||||
import { test } from '../../test';
|
||||
|
||||
export default test({
|
||||
mode: ['server']
|
||||
});
|
@ -0,0 +1,59 @@
|
||||
import * as $ from "svelte/internal/server";
|
||||
|
||||
export default function Server_deriveds($$payload, $$props) {
|
||||
$.push();
|
||||
|
||||
// destructuring stuff on the server needs a bit more code
|
||||
// so that every identifier is a function
|
||||
let stuff = {
|
||||
foo: true,
|
||||
bar: [1, 2, { baz: 'baz' }]
|
||||
};
|
||||
|
||||
let {
|
||||
foo: foo_1,
|
||||
bar: [a_1, b_1, { baz: baz_1 }]
|
||||
} = stuff,
|
||||
foo = () => foo_1,
|
||||
a = () => a_1,
|
||||
b = () => b_1,
|
||||
baz = () => baz_1;
|
||||
|
||||
let stuff2 = [1, 2, 3];
|
||||
|
||||
let [d_1, e_1, f_1] = stuff2,
|
||||
d = () => d_1,
|
||||
e = () => e_1,
|
||||
f = () => f_1;
|
||||
|
||||
let count = 0;
|
||||
let double = () => count * 2;
|
||||
let identifier = () => count;
|
||||
let dot_by = () => () => count;
|
||||
|
||||
class Test {
|
||||
state = 0;
|
||||
#der = () => this.state * 2;
|
||||
|
||||
get der() {
|
||||
return this.#der();
|
||||
}
|
||||
|
||||
#der_by = () => this.state;
|
||||
|
||||
get der_by() {
|
||||
return this.#der_by();
|
||||
}
|
||||
|
||||
#identifier = () => this.state;
|
||||
|
||||
get identifier() {
|
||||
return this.#identifier();
|
||||
}
|
||||
}
|
||||
|
||||
const test = new Test();
|
||||
|
||||
$$payload.out += `<!---->${$.escape(foo?.())} ${$.escape(a?.())} ${$.escape(b?.())} ${$.escape(baz?.())} ${$.escape(d?.())} ${$.escape(e?.())} ${$.escape(f?.())} ${$.escape(double?.())} ${$.escape(identifier?.())} ${$.escape(dot_by?.())} ${$.escape(test.der)} ${$.escape(test.der_by)} ${$.escape(test.identifier)}`;
|
||||
$.pop();
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<script>
|
||||
// destructuring stuff on the server needs a bit more code
|
||||
// so that every identifier is a function
|
||||
let stuff = $state({ foo: true, bar: [1, 2, {baz: 'baz'}] });
|
||||
let { foo, bar: [a, b, { baz }]} = $derived(stuff);
|
||||
|
||||
let stuff2 = $state([1, 2, 3]);
|
||||
let [d, e, f] = $derived(stuff2);
|
||||
|
||||
let count = $state(0);
|
||||
let double = $derived(count * 2);
|
||||
let identifier = $derived(count);
|
||||
let dot_by = $derived(()=>count);
|
||||
|
||||
class Test{
|
||||
state = $state(0);
|
||||
der = $derived(this.state * 2);
|
||||
der_by = $derived.by(()=>this.state);
|
||||
identifier = $derived(this.state);
|
||||
}
|
||||
|
||||
const test = new Test();
|
||||
</script>
|
||||
|
||||
{foo} {a} {b} {baz} {d} {e} {f} {double} {identifier} {dot_by} {test.der} {test.der_by} {test.identifier}
|
Loading…
Reference in new issue