1 |
|
2 |
|
3 |
|
4 |
|
5 | "use strict";
|
6 |
|
7 | const DependenciesBlockVariable = require("./DependenciesBlockVariable");
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | class DependenciesBlock {
|
17 | constructor() {
|
18 |
|
19 | this.dependencies = [];
|
20 |
|
21 | this.blocks = [];
|
22 |
|
23 | this.variables = [];
|
24 | }
|
25 |
|
26 | |
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | addBlock(block) {
|
34 | this.blocks.push(block);
|
35 | block.parent = this;
|
36 | }
|
37 |
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | addVariable(name, expression, dependencies) {
|
45 | for (let v of this.variables) {
|
46 | if (v.name === name && v.expression === expression) {
|
47 | return;
|
48 | }
|
49 | }
|
50 | this.variables.push(
|
51 | new DependenciesBlockVariable(name, expression, dependencies)
|
52 | );
|
53 | }
|
54 |
|
55 | |
56 |
|
57 |
|
58 |
|
59 |
|
60 | addDependency(dependency) {
|
61 | this.dependencies.push(dependency);
|
62 | }
|
63 |
|
64 | |
65 |
|
66 |
|
67 |
|
68 | removeDependency(dependency) {
|
69 | const idx = this.dependencies.indexOf(dependency);
|
70 | if (idx >= 0) {
|
71 | this.dependencies.splice(idx, 1);
|
72 | }
|
73 | }
|
74 |
|
75 | |
76 |
|
77 |
|
78 |
|
79 | updateHash(hash) {
|
80 | for (const dep of this.dependencies) dep.updateHash(hash);
|
81 | for (const block of this.blocks) block.updateHash(hash);
|
82 | for (const variable of this.variables) variable.updateHash(hash);
|
83 | }
|
84 |
|
85 | disconnect() {
|
86 | for (const dep of this.dependencies) dep.disconnect();
|
87 | for (const block of this.blocks) block.disconnect();
|
88 | for (const variable of this.variables) variable.disconnect();
|
89 | }
|
90 |
|
91 | unseal() {
|
92 | for (const block of this.blocks) block.unseal();
|
93 | }
|
94 |
|
95 | |
96 |
|
97 |
|
98 |
|
99 | hasDependencies(filter) {
|
100 | if (filter) {
|
101 | for (const dep of this.dependencies) {
|
102 | if (filter(dep)) return true;
|
103 | }
|
104 | } else {
|
105 | if (this.dependencies.length > 0) {
|
106 | return true;
|
107 | }
|
108 | }
|
109 |
|
110 | for (const block of this.blocks) {
|
111 | if (block.hasDependencies(filter)) return true;
|
112 | }
|
113 | for (const variable of this.variables) {
|
114 | if (variable.hasDependencies(filter)) return true;
|
115 | }
|
116 | return false;
|
117 | }
|
118 |
|
119 | sortItems() {
|
120 | for (const block of this.blocks) block.sortItems();
|
121 | }
|
122 | }
|
123 |
|
124 | module.exports = DependenciesBlock;
|