MCPcopy Create free account
hub / github.com/ethanniser/the-beth-stack / BethRenderCache

Class BethRenderCache

packages/beth-stack/src/cache/render.ts:41–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39 | { type: "error"; error: any };
40
41export class BethRenderCache {
42 public dedupeCache: WeakMap<Function, Map<Array<any>, CachedValue<any>>>;
43 public streamController: ReadableStreamDefaultController<string> | undefined;
44 public counter: number;
45 private suspenseMap: Map<Children, number>;
46 public sentFirstChunk: boolean;
47
48 constructor() {
49 this.dedupeCache = new WeakMap();
50 this.streamController = undefined;
51 this.counter = 1;
52 this.suspenseMap = new Map();
53 this.sentFirstChunk = false;
54 }
55
56 public reset() {
57 this.dedupeCache = new WeakMap();
58 this.streamController = undefined;
59 this.counter = 1;
60 this.suspenseMap = new Map();
61 this.sentFirstChunk = false;
62 }
63
64 public registerChild(child: Children[]): number {
65 const id = this.counter++;
66 this.suspenseMap.set(child, id);
67 return id;
68 }
69
70 public dismissChild(child: Children[]): number | undefined {
71 const id = this.suspenseMap.get(child);
72 if (id) {
73 this.suspenseMap.delete(child);
74 }
75 return id;
76 }
77
78 public closeNow() {
79 this.streamController?.close();
80 this.reset();
81 }
82
83 public checkIfEndAndClose() {
84 if (this.suspenseMap.size === 0) {
85 this.closeNow();
86 }
87 }
88}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected