-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
58 lines (48 loc) · 1.43 KB
/
types.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
54
55
56
57
58
// TODO - Need to decide what needs to be exported and export one statement.
export type SerializedTreeNode<T> = {
parentId: string;
payload: T;
};
export type SerializedRootNode<T> = {
parentId: null;
payload: T;
};
export type SerializedTree<T> = {
[nodeId: string]: SerializedTreeNode<T> | SerializedRootNode<T>;
};
type TreeNodeBase<T> = {
parentId: string;
nodeId: string;
payload: T;
};
export type TreeNodeRef<T> = TreeNodeBase<T> & {
children: {
[nodeId: string]: TreeNodeRef<T>;
} | null;
};
export type TreeNode<T> = TreeNodeBase<T> & {
childrenIds: string[];
};
export type TreeNodeRefDictionary<T> = {
[nodeId: string]: TreeNodeRef<T>;
};
// This is the same shape as DirectedGraphTree._tree
// Some reason that is not typed? Also this shape maybe found
// somewhere else.
//
// ultimately the goal of DirectedTreeGraph:
// SerializedTreeNode -> TreeNodeRefDictionary
// TreeNodeRefDictionary -> SerializedTreeNode
// except instead of using word serial we've got to using
// the word json
// export type payloadConverterType = <T>(payload: any) => T;
export interface IIncrementor {
readonly nextValue: number; // should increase each time its called
readonly currentValue: number; //
}
export type VisitorNodeType = "branch" | "leaf" | "all";
export interface IVisitor<T> {
nodeType: VisitorNodeType;
visit: (parentId: string, nodeId: string, payload: T) => void;
startNodeId?: string;
}