Code coverage report for src/operator/observeOn.ts

Statements: 100% (39 / 39)      Branches: 83.33% (5 / 6)      Functions: 100% (13 / 13)      Lines: 100% (29 / 29)      Ignored: none     

All files » src/operator/ » observeOn.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 47 48 49 50 51 52 53 54 55        1 1   13 7     1 7     1 7   1   1 1 28     1 12 16 12     1 28         1 21     1 1     1 6   1   1 28 28   1
import {Observable} from '../Observable';
import {Scheduler} from '../Scheduler';
import {Operator} from '../Operator';
import {Observer} from '../Observer';
import {Subscriber} from '../Subscriber';
import {Notification} from '../Notification';
 
export function observeOn<T>(scheduler: Scheduler, delay: number = 0): Observable<T> {
  return this.lift(new ObserveOnOperator(scheduler, delay));
}
 
export class ObserveOnOperator<T> implements Operator<T, T> {
  constructor(private scheduler: Scheduler, Iprivate delay: number = 0) {
  }
 
  call(subscriber: Subscriber<T>): Subscriber<T> {
    return new ObserveOnSubscriber(subscriber, this.scheduler, this.delay);
  }
}
 
export class ObserveOnSubscriber<T> extends Subscriber<T> {
  static dispatch({ notification, destination }) {
    notification.observe(destination);
  }
 
  constructor(destination: Subscriber<T>,
              private scheduler: Scheduler,
              private delay: number = 0) {
    super(destination);
  }
 
  private scheduleMessage(notification: Notification<any>): void {
     this.add(this.scheduler.schedule(ObserveOnSubscriber.dispatch,
                                      this.delay,
                                      new ObserveOnMessage(notification, this.destination)));
   }
 
  protected _next(value: T): void {
    this.scheduleMessage(Notification.createNext(value));
  }
 
  protected _error(err: any): void {
    this.scheduleMessage(Notification.createError(err));
  }
 
  protected _complete(): void {
    this.scheduleMessage(Notification.createComplete());
  }
}
 
class ObserveOnMessage {
  constructor(public notification: Notification<any>,
              public destination: Observer<any>) {
  }
}