forked from TuanManhCao/digital-garden
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.ts
More file actions
30 lines (26 loc) · 826 Bytes
/
context.ts
File metadata and controls
30 lines (26 loc) · 826 Bytes
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
import { getCacheData } from "volglass-backend";
import { getFlattenArray, TreeData } from "./markdown";
import { SearchData } from "./search";
interface SharedContext {
cacheData: any;
tree: TreeData;
flattenNodes: TreeData[];
searchIndex: SearchData[];
}
let sharedContext: SharedContext | null = null;
export const getSharedContext = async (): Promise<SharedContext> => {
if (sharedContext !== null) {
return sharedContext;
}
const [cacheData, rawTreeData, rawSearchIndex] = await getCacheData();
const tree: TreeData = JSON.parse(rawTreeData);
const searchIndex: SearchData[] = JSON.parse(rawSearchIndex);
const flattenNodes = getFlattenArray(tree);
sharedContext = {
cacheData,
tree,
flattenNodes,
searchIndex,
}
return sharedContext;
};