Skip to content

Commit 142b90e

Browse files
committed
avoid using forEach
1 parent 7a95b8c commit 142b90e

File tree

1 file changed

+28
-17
lines changed

1 file changed

+28
-17
lines changed

lib/DependenciesBlock.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66

77
const DependenciesBlockVariable = require("./DependenciesBlockVariable");
88

9-
const disconnect = i => i.disconnect();
10-
11-
const unseal = i => i.unseal();
12-
139
class DependenciesBlock {
1410
constructor() {
1511
this.dependencies = [];
@@ -42,39 +38,54 @@ class DependenciesBlock {
4238
}
4339

4440
updateHash(hash) {
45-
const updateHash = i => i.updateHash(hash);
46-
47-
this.dependencies.forEach(updateHash);
48-
this.blocks.forEach(updateHash);
49-
this.variables.forEach(updateHash);
41+
for(const dep of this.dependencies)
42+
dep.updateHash(hash);
43+
for(const block of this.blocks)
44+
block.updateHash(hash);
45+
for(const variable of this.variables)
46+
variable.updateHash(hash);
5047
}
5148

5249
disconnect() {
53-
this.dependencies.forEach(disconnect);
54-
this.blocks.forEach(disconnect);
55-
this.variables.forEach(disconnect);
50+
for(const dep of this.dependencies)
51+
dep.disconnect();
52+
for(const block of this.blocks)
53+
block.disconnect();
54+
for(const variable of this.variables)
55+
variable.disconnect();
5656
}
5757

5858
unseal() {
59-
this.blocks.forEach(unseal);
59+
for(const block of this.blocks)
60+
block.unseal();
6061
}
6162

6263
hasDependencies(filter) {
6364
if(filter) {
64-
if(this.dependencies.some(filter)) {
65-
return true;
65+
for(const dep of this.dependencies) {
66+
if(filter(dep))
67+
return true;
6668
}
6769
} else {
6870
if(this.dependencies.length > 0) {
6971
return true;
7072
}
7173
}
7274

73-
return this.blocks.concat(this.variables).some(item => item.hasDependencies(filter));
75+
for(const block of this.blocks) {
76+
if(block.hasDependencies(filter))
77+
return true;
78+
}
79+
for(const variable of this.variables) {
80+
if(variable.hasDependencies(filter))
81+
return true;
82+
}
83+
return false;
7484
}
7585

7686
sortItems() {
77-
this.blocks.forEach(block => block.sortItems());
87+
for(const block of this.blocks)
88+
block.sortItems();
7889
}
7990
}
8091

0 commit comments

Comments
 (0)