-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathItem.server.ts
34 lines (28 loc) · 996 Bytes
/
Item.server.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { Computed } from "async-reactivity";
import BaseItem from './Item.js';
import { get, subscribe, unsubscribe } from '../data.js';
export default class Item extends BaseItem {
readonly text: Computed<Promise<string | undefined>>;
readonly done: Computed<Promise<boolean | undefined>>;
readonly invalidate: Function;
constructor(id: string) {
super(id);
this.text = new Computed(async () => {
const item = await get(id);
return item?.text;
}, undefined, 3 * 1000);
this.done = new Computed(async () => {
const item = await get(id);
return item?.done;
}, undefined, 3 * 1000);
this.invalidate = () => {
this.text.forceInvalidate();
this.done.forceInvalidate();
};
subscribe(this.invalidate);
}
[Symbol.dispose]() {
unsubscribe(this.invalidate);
super[Symbol.dispose]();
}
}