thunkify-deriveds
Rich Harris 21 hours ago
parent 1699754496
commit 7c4f5956d4

@ -0,0 +1,3 @@
import { test } from '../../test';
export default test({});

@ -0,0 +1,29 @@
<script>
import { reset, increment, get, count } from './state.svelte.js';
reset();
get();
increment();
get();
// non-render-bound deriveds recalculate
if (count !== 2) {
throw new Error(`count was ${count}`);
}
let local_count = 0;
let s = $state(0);
let d = $derived.by(() => {
local_count += 1;
return s * 2;
});
d;
d;
// render-bound deriveds do not
if (local_count !== 1) {
throw new Error(`local_count was ${local_count}`);
}
</script>

@ -0,0 +1,20 @@
let s = $state(0);
let d = $derived.by(() => {
count += 1;
return s * 2;
});
export let count = 0;
export function reset() {
count = 0;
s = 0;
}
export function increment() {
s += 1;
}
export function get() {
return d;
}
Loading…
Cancel
Save