-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
82 lines (70 loc) · 2.26 KB
/
index.ts
File metadata and controls
82 lines (70 loc) · 2.26 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import { CCStoreAutoSaver } from "./autoSaver";
import { CCComponentStore } from "./component";
import { CCComponentPinStore } from "./componentPin";
import { CCConnectionStore } from "./connection";
import * as intrinsics from "./intrinsics/definitions";
import { CCNodeStore } from "./node";
import { CCNodePinStore } from "./nodePin";
import TransactionManager from "./transaction";
/**
* Store of components, nodes, pins, and connections
*/
export default class CCStore {
components: CCComponentStore;
nodes: CCNodeStore;
componentPins: CCComponentPinStore;
nodePins: CCNodePinStore;
connections: CCConnectionStore;
transactionManager: TransactionManager;
autoSaver: CCStoreAutoSaver;
/**
* Constructor of CCStore
* @param rootComponent root component
* @param props properties of store from JSON used when restoring store from JSON
*/
constructor() {
this.components = new CCComponentStore(this);
this.nodes = new CCNodeStore(this);
this.componentPins = new CCComponentPinStore(this);
this.nodePins = new CCNodePinStore(this);
this.connections = new CCConnectionStore(this);
this.transactionManager = new TransactionManager();
this.autoSaver = new CCStoreAutoSaver(this);
for (const definition of Object.values(intrinsics.definitions)) {
this.components.register(definition.component);
for (const pin of definition.allPins) {
this.componentPins.register(pin);
}
}
}
mount() {
this.components.mount();
this.nodes.mount();
this.componentPins.mount();
this.nodePins.mount();
this.connections.mount();
}
/**
* Get the JSON representation of the store
* @returns JSON representation of the store
*/
toJSON() {
return JSON.stringify({
// Only export non-intrinsic components
components: this.components.getMany().filter((c) => !c.intrinsicType),
nodes: this.nodes.getMany(),
componentPins: this.componentPins.getMany(),
nodePins: this.nodePins.getMany(),
connections: this.connections.getMany(),
});
}
importJson(json: string) {
const { components, nodes, componentPins, nodePins, connections } =
JSON.parse(json);
this.components.import(components);
this.nodes.import(nodes);
this.componentPins.import(componentPins);
this.nodePins.import(nodePins);
this.connections.import(connections);
}
}