Code coverage report for src/scheduler/AnimationFrameAction.ts

Statements: 28.57% (8 / 28)      Branches: 0% (0 / 10)      Functions: 25% (1 / 4)      Lines: 24% (6 / 25)      Ignored: none     

All files » src/scheduler/ » AnimationFrameAction.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40  1 1   2   1                                 1                             1  
import {Action} from './Action';
import {FutureAction} from './FutureAction';
import {AnimationFrame} from '../util/AnimationFrame';
 
export class AnimationFrameAction<T> extends FutureAction<T> {
 
  protected _schedule(state?: any, delay: number = 0): Action {
    if (delay > 0) {
      return super._schedule(state, delay);
    }
    this.delay = delay;
    this.state = state;
    const {scheduler} = this;
    scheduler.actions.push(this);
    if (!scheduler.scheduledId) {
      scheduler.scheduledId = AnimationFrame.requestAnimationFrame(() => {
        scheduler.scheduledId = null;
        scheduler.flush();
      });
    }
    return this;
  }
 
  protected _unsubscribe(): void {
 
    const {scheduler} = this;
    const {scheduledId, actions} = scheduler;
 
    super._unsubscribe();
 
    if (actions.length === 0) {
      scheduler.active = false;
      if (scheduledId != null) {
        scheduler.scheduledId = null;
        AnimationFrame.cancelAnimationFrame(scheduledId);
      }
    }
  }
}