Skip to content

Commit c79c902

Browse files
committed
add test
1 parent 83e1823 commit c79c902

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { test } from '../../test';
2+
3+
export default test({
4+
html: `3`
5+
});
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<script module>
2+
import { untrack } from 'svelte'
3+
import { SvelteMap } from 'svelte/reactivity'
4+
5+
class Foo {
6+
id
7+
updateTime = $state(Date.now())
8+
9+
constructor(id) {
10+
this.id = id
11+
}
12+
}
13+
14+
class Store {
15+
cache = new SvelteMap()
16+
ids = $state([1, 2, 3])
17+
18+
getOrDefault(id) {
19+
let ret = this.cache.get(id)
20+
21+
if (ret) {
22+
return ret
23+
}
24+
25+
ret = untrack(() => {
26+
ret = new Foo(id)
27+
this.cache.set(id, ret)
28+
return ret
29+
})
30+
this.cache.get(id)
31+
32+
return ret
33+
}
34+
35+
get values() {
36+
return this.ids.map(id => this.getOrDefault(id)).sort((a, b) => b.updateTime - a.updateTime)
37+
}
38+
}
39+
40+
const store = new Store()
41+
</script>
42+
43+
<script>
44+
const test = $derived.by(() => store.values.length)
45+
</script>
46+
47+
{test}

0 commit comments

Comments
 (0)