deno.land / x / replicache@v10.0.0-beta.0 / kv / write-impl-base.ts

write-impl-base.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import type {Read, Value} from './store';
export const deleteSentinel = Symbol();export type DeleteSentinel = typeof deleteSentinel;
export class WriteImplBase { protected readonly _pending: Map<string, Value | DeleteSentinel> = new Map(); private readonly _read: Read;
constructor(read: Read) { this._read = read; }
async has(key: string): Promise<boolean> { switch (this._pending.get(key)) { case undefined: return this._read.has(key); case deleteSentinel: return false; default: return true; } }
async get(key: string): Promise<Value | undefined> { const v = this._pending.get(key); switch (v) { case deleteSentinel: return undefined; case undefined: return this._read.get(key); default: return v; } }
async put(key: string, value: Value): Promise<void> { this._pending.set(key, value); }
async del(key: string): Promise<void> { this._pending.set(key, deleteSentinel); }
release(): void { this._read.release(); }
get closed(): boolean { return this._read.closed; }}
replicache

Version Info

Tagged at
2 years ago