Skip to content

Commit 1f820e5

Browse files
committed
refactor: update variable checker and waiting for promises
1 parent 101a6de commit 1f820e5

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/state.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,14 @@ export class State {
7979

8080
addVariable(variable, entityID) {
8181
const variables = this.variables.get(variable) || []
82+
if (variables.includes(entityID)) return
8283
this.variables.set(variable, [...variables, entityID])
8384
}
8485

8586
addEntityVariable(groupID, variable, entityID) {
8687
const key = `${groupID}.${variable}`
8788
const variables = this.entityVariables.get(key) || []
89+
if (variables.includes(entityID)) return
8890
this.entityVariables.set(key, [...variables, entityID])
8991
}
9092

@@ -205,10 +207,14 @@ export class State {
205207
}
206208

207209
evaluate() {
208-
Array.from(this.entities.values()).forEach(async (entity) => {
209-
entity.attributes.evaluate()
210+
const promises = []
211+
212+
Array.from(this.entities.values()).forEach((entity) => {
213+
promises.push(entity.attributes.evaluate())
210214
})
211215

216+
await Promise.all(promises)
217+
212218
this.attachVariableHelpers(Array.from(this.variables.keys()))
213219
this.shouldUpdate = true
214220
}

0 commit comments

Comments
 (0)