File tree Expand file tree Collapse file tree 6 files changed +85
-2
lines changed Expand file tree Collapse file tree 6 files changed +85
-2
lines changed Original file line number Diff line number Diff line change @@ -123,15 +123,18 @@ import {ArgumentOutOfRangeError} from './util/ArgumentOutOfRangeError';
123
123
import { ObjectUnsubscribedError } from './util/ObjectUnsubscribedError' ;
124
124
import { asap } from './scheduler/asap' ;
125
125
import { queue } from './scheduler/queue' ;
126
+ import { animationFrame } from './scheduler/animationFrame' ;
126
127
import { AsapScheduler } from './scheduler/AsapScheduler' ;
127
128
import { QueueScheduler } from './scheduler/QueueScheduler' ;
129
+ import { AnimationFrameScheduler } from './scheduler/AnimationFrameScheduler' ;
128
130
import { rxSubscriber } from './symbol/rxSubscriber' ;
129
131
/* tslint:enable:no-unused-variable */
130
132
131
133
/* tslint:disable:no-var-keyword */
132
134
var Scheduler = {
133
135
asap,
134
- queue
136
+ queue,
137
+ animationFrame
135
138
} ;
136
139
137
140
var Symbol = {
Original file line number Diff line number Diff line change
1
+ import { Action } from './Action' ;
2
+ import { FutureAction } from './FutureAction' ;
3
+ import { AnimationFrame } from '../util/AnimationFrame' ;
4
+
5
+ export class AnimationFrameAction < T > extends FutureAction < T > {
6
+
7
+ _schedule ( state ?: any , delay : number = 0 ) : Action {
8
+ if ( delay > 0 ) {
9
+ return super . _schedule ( state , delay ) ;
10
+ }
11
+ this . delay = delay ;
12
+ this . state = state ;
13
+ const { scheduler} = this ;
14
+ scheduler . actions . push ( this ) ;
15
+ if ( ! scheduler . scheduledId ) {
16
+ scheduler . scheduledId = AnimationFrame . requestAnimationFrame ( ( ) => {
17
+ scheduler . scheduledId = null ;
18
+ scheduler . flush ( ) ;
19
+ } ) ;
20
+ }
21
+ return this ;
22
+ }
23
+
24
+ _unsubscribe ( ) : void {
25
+
26
+ const { scheduler} = this ;
27
+ const { scheduledId, actions} = scheduler ;
28
+
29
+ super . _unsubscribe ( ) ;
30
+
31
+ if ( actions . length === 0 ) {
32
+ scheduler . active = false ;
33
+ if ( scheduledId != null ) {
34
+ scheduler . scheduledId = null ;
35
+ AnimationFrame . cancelAnimationFrame ( scheduledId ) ;
36
+ }
37
+ }
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ import { Action } from './Action' ;
2
+ import { Subscription } from '../Subscription' ;
3
+ import { QueueScheduler } from './QueueScheduler' ;
4
+ import { AnimationFrameAction } from './AnimationFrameAction' ;
5
+
6
+ export class AnimationFrameScheduler extends QueueScheduler {
7
+ scheduleNow < T > ( work : ( x ?: any ) => Subscription , state ?: any ) : Action {
8
+ return new AnimationFrameAction ( this , work ) . schedule ( state ) ;
9
+ }
10
+ }
Original file line number Diff line number Diff line change @@ -4,7 +4,6 @@ import {Subscription} from '../Subscription';
4
4
import { QueueScheduler } from './QueueScheduler' ;
5
5
6
6
export class AsapScheduler extends QueueScheduler {
7
- public scheduledId : number = null ;
8
7
scheduleNow < T > ( work : ( x ?: any ) => Subscription , state ?: any ) : Action {
9
8
return new AsapAction ( this , work ) . schedule ( state ) ;
10
9
}
Original file line number Diff line number Diff line change
1
+ import { AnimationFrameScheduler } from './AnimationFrameScheduler' ;
2
+
3
+ export const animationFrame = new AnimationFrameScheduler ( ) ;
Original file line number Diff line number Diff line change
1
+ import { root } from './root' ;
2
+
3
+ export class RequestAnimationFrameDefinition {
4
+ cancelAnimationFrame : ( handle : number ) => void ;
5
+ requestAnimationFrame : ( cb : ( ) => void ) => number ;
6
+ constructor ( root : any ) {
7
+ if ( root . requestAnimationFrame ) {
8
+ this . cancelAnimationFrame = root . cancelAnimationFrame ;
9
+ this . requestAnimationFrame = root . requestAnimationFrame ;
10
+ } else if ( root . mozRequestAnimationFrame ) {
11
+ this . cancelAnimationFrame = root . mozCancelAnimationFrame ;
12
+ this . requestAnimationFrame = root . mozRequestAnimationFrame ;
13
+ } else if ( root . webkitRequestAnimationFrame ) {
14
+ this . cancelAnimationFrame = root . webkitCancelAnimationFrame ;
15
+ this . requestAnimationFrame = root . webkitRequestAnimationFrame ;
16
+ } else if ( root . msRequestAnimationFrame ) {
17
+ this . cancelAnimationFrame = root . msCancelAnimationFrame ;
18
+ this . requestAnimationFrame = root . msRequestAnimationFrame ;
19
+ } else if ( root . oRequestAnimationFrame ) {
20
+ this . cancelAnimationFrame = root . oCancelAnimationFrame ;
21
+ this . requestAnimationFrame = root . oRequestAnimationFrame ;
22
+ } else {
23
+ this . cancelAnimationFrame = root . clearTimeout ;
24
+ this . requestAnimationFrame = function ( cb ) { return root . setTimeout ( cb , 1000 / 60 ) ; } ;
25
+ }
26
+ }
27
+ }
28
+
29
+ export const AnimationFrame = new RequestAnimationFrameDefinition ( root ) ;
You can’t perform that action at this time.
0 commit comments