-
Notifications
You must be signed in to change notification settings - Fork 10
/
NODE.js
50 lines (40 loc) · 1.18 KB
/
NODE.js
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
const graph = require("../graph");
const transaction = require("../transaction");
let sequence = 0;
class NODE {
constructor(key) {
this.key = key.toString();
this.next = {};
this.previous = {};
this.sequence = sequence++;
}
before() {}
run() {}
beforeGraph() {}
graph() {}
after() {}
// TODO Move this to graph
static register(key, node) {
transaction.register(graph.$, key, node);
}
static replace(sourceKey, targetNode) {
transaction.register(targetNode.block, graph.$[sourceKey].block);
for (let node in graph.$[sourceKey].next) {
transaction.register(
targetNode.next,
node,
graph.$[sourceKey].next[node]
);
transaction.register(graph.$[sourceKey].next, node, undefined);
}
for (let node in graph.$[sourceKey].previous) {
transaction.register(graph.$[node].next, sourceKey, undefined);
}
transaction.register(graph.$, sourceKey, targetNode);
}
static direct(sourceKey, targetKey, targetNode) {
transaction.register(graph.$[sourceKey].next, targetKey, targetNode);
transaction.register(targetNode.previous, sourceKey, graph.$[sourceKey]);
}
}
module.exports = NODE;