@@ -14,17 +14,7 @@ export default class VirtualTimeScheduler implements Scheduler {
14
14
return 0 ;
15
15
}
16
16
17
- sortActions ( ) {
18
- if ( ! this . sorted ) {
19
- ( < VirtualAction < any > [ ] > this . actions ) . sort ( ( a , b ) => {
20
- return a . delay === b . delay ? ( a . index > b . index ? 1 : - 1 ) : ( a . delay > b . delay ? 1 : - 1 ) ;
21
- } ) ;
22
- this . sorted = true ;
23
- }
24
- }
25
-
26
17
flush ( ) {
27
- this . sortActions ( ) ;
28
18
const actions = this . actions ;
29
19
while ( actions . length > 0 ) {
30
20
let action = actions . shift ( ) ;
@@ -33,6 +23,20 @@ export default class VirtualTimeScheduler implements Scheduler {
33
23
}
34
24
this . frame = 0 ;
35
25
}
26
+
27
+ addAction < T > ( action : Action ) {
28
+ const findDelay = action . delay ;
29
+ const actions = this . actions ;
30
+ const len = actions . length ;
31
+ const vaction = < VirtualAction < T > > action ;
32
+
33
+
34
+ actions . push ( action ) ;
35
+
36
+ actions . sort ( ( a :VirtualAction < T > , b :VirtualAction < T > ) => {
37
+ return ( a . delay === b . delay ) ? ( a . index === b . index ? 0 : ( a . index > b . index ? 1 : - 1 ) ) : ( a . delay > b . delay ? 1 : - 1 ) ;
38
+ } ) ;
39
+ }
36
40
37
41
schedule < T > ( work : ( x ?: any ) => Subscription < T > | void , delay : number = 0 , state ?: any ) : Subscription < T > {
38
42
this . sorted = false ;
@@ -59,7 +63,7 @@ class VirtualAction<T> extends Subscription<T> implements Action {
59
63
new VirtualAction ( scheduler , this . work , scheduler . index += 1 ) ;
60
64
action . state = state ;
61
65
action . delay = scheduler . frame + delay ;
62
- scheduler . actions . push ( action ) ;
66
+ scheduler . addAction ( action ) ;
63
67
return this ;
64
68
}
65
69
0 commit comments