@@ -17,29 +17,37 @@ function pruneTickObjects(activities) {
17
17
// Remove one TickObject on each pass until none is left anymore
18
18
// not super efficient, but simplest especially to handle
19
19
// multiple TickObjects in a row
20
- let foundTickObject = true ;
20
+ const tickObject = {
21
+ found : true ,
22
+ index : null ,
23
+ data : null
24
+ } ;
21
25
22
- while ( foundTickObject ) {
23
- foundTickObject = false ;
24
- let tickObjectIdx = - 1 ;
26
+ while ( tickObject . found ) {
25
27
for ( let i = 0 ; i < activities . length ; i ++ ) {
26
- if ( activities [ i ] . type !== 'TickObject' ) continue ;
27
- tickObjectIdx = i ;
28
- break ;
28
+ if ( activities [ i ] . type === 'TickObject' ) {
29
+ tickObject . index = i ;
30
+ break ;
31
+ } else if ( i + 1 === activities . length ) {
32
+ tickObject . found = false ;
33
+ }
29
34
}
30
35
31
- if ( tickObjectIdx >= 0 ) {
32
- foundTickObject = true ;
33
-
36
+ if ( tickObject . found ) {
34
37
// Point all triggerAsyncIds that point to the tickObject
35
38
// to its triggerAsyncId and finally remove it from the activities
36
- const tickObject = activities [ tickObjectIdx ] ;
37
- const newTriggerId = tickObject . triggerAsyncId ;
38
- const oldTriggerId = tickObject . uid ;
39
+ tickObject . data = activities [ tickObject . index ] ;
40
+ const triggerId = {
41
+ new : tickObject . data . triggerAsyncId ,
42
+ old : tickObject . data . uid
43
+ } ;
44
+
39
45
activities . forEach ( function repointTriggerId ( x ) {
40
- if ( x . triggerAsyncId === oldTriggerId ) x . triggerAsyncId = newTriggerId ;
46
+ if ( x . triggerAsyncId === triggerId . old )
47
+ x . triggerAsyncId = triggerId . new ;
41
48
} ) ;
42
- activities . splice ( tickObjectIdx , 1 ) ;
49
+
50
+ activities . splice ( tickObject . index , 1 ) ;
43
51
}
44
52
}
45
53
return activities ;
0 commit comments