()
| 169 | |
| 170 | // Recomputes state, incorporating children's states |
| 171 | private updateTotalState() { |
| 172 | let allChildrenDone = true; |
| 173 | const state = { ...this.selfState }; |
| 174 | this.allTasks.forEach(child => { |
| 175 | const childState = child.state; |
| 176 | |
| 177 | if (!child.isDone) { |
| 178 | allChildrenDone = false; |
| 179 | } |
| 180 | |
| 181 | state.current += childState.current; |
| 182 | if (state.end !== undefined) { |
| 183 | if (childState.done) { |
| 184 | state.end += childState.current; |
| 185 | } else if (childState.end !== undefined) { |
| 186 | state.end += childState.end; |
| 187 | } else { |
| 188 | state.end = undefined; |
| 189 | } |
| 190 | } |
| 191 | }); |
| 192 | |
| 193 | this.isDone = allChildrenDone && !!this.selfState.done; |
| 194 | if (!allChildrenDone) { |
| 195 | state.done = false; |
| 196 | } |
| 197 | |
| 198 | if (!state.done && this.state.done) { |
| 199 | // This shouldn't happen |
| 200 | throw new Error("Progress transition from done => !done"); |
| 201 | } |
| 202 | |
| 203 | this.state = state; |
| 204 | } |
| 205 | |
| 206 | // Called by a child when its state changes |
| 207 | private reportChildState() { |
no test coverage detected