Refactor to improve iterations
- Use function abstractions (such as map, reduce, filter etc.) over for-of loops to gain benefits of having less side effects and easier readability. - Enable `downLevelIterations` for writing modern code with lazy evaluation. - Refactor for of loops to named abstractions to clearly express their intentions without needing to analyse the loop itself. - Add missing cases for changes that had no tests.
This commit is contained in:
@@ -52,14 +52,12 @@ class SchedulerMock {
|
||||
|
||||
public tickNext(ms: number) {
|
||||
const newTime = this.currentTime + ms;
|
||||
let newActions = this.scheduledActions;
|
||||
for (const action of this.scheduledActions) {
|
||||
if (newTime >= action.time) {
|
||||
newActions = newActions.filter((a) => a !== action);
|
||||
action.action();
|
||||
}
|
||||
const dueActions = this.scheduledActions
|
||||
.filter((action) => newTime >= action.time);
|
||||
for (const action of dueActions) {
|
||||
action.action();
|
||||
}
|
||||
this.scheduledActions = newActions;
|
||||
this.scheduledActions = this.scheduledActions.filter((action) => !dueActions.includes(action));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user