Code coverage report for src/observable/IntervalObservable.ts

Statements: 100% (33 / 33)      Branches: 83.33% (15 / 18)      Functions: 100% (5 / 5)      Lines: 100% (25 / 25)      Ignored: none     

All files » src/observable/ » IntervalObservable.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 41 42 43 44 45 46  1   1 1   1 8 6     1 28   28   28 3     25   25     6 6 6 1   6 1       1 5 5 5   5       1  
import {Subscriber} from '../Subscriber';
import {isNumeric} from '../util/isNumeric';
import {Scheduler} from '../Scheduler';
import {Observable} from '../Observable';
import {asap} from '../scheduler/asap';
 
export class IntervalObservable extends Observable<number> {
  static create(Iperiod: number = 0, scheduler: Scheduler = asap): Observable<number> {
    return new IntervalObservable(period, scheduler);
  }
 
  static dispatch(state: any): void {
    const { index, subscriber, period } = state;
 
    subscriber.next(index);
 
    if (subscriber.isUnsubscribed) {
      return;
    }
 
    state.index += 1;
 
    (<any> this).schedule(state, period);
  }
 
  constructor(Iprivate period: number = 0, Iprivate scheduler: Scheduler = asap) {
    super();
    if (!isNumeric(period) || period < 0) {
      this.period = 0;
    }
    if (!scheduler || typeof scheduler.schedule !== 'function') {
      this.scheduler = asap;
    }
  }
 
  protected _subscribe(subscriber: Subscriber<number>) {
    const index = 0;
    const period = this.period;
    const scheduler = this.scheduler;
 
    subscriber.add(scheduler.schedule(IntervalObservable.dispatch, period, {
      index, subscriber, period
    }));
  }
}