Code coverage report for src/operator/mapTo.ts

Statements: 100% (18 / 18)      Branches: 100% (0 / 0)      Functions: 100% (7 / 7)      Lines: 100% (16 / 16)      Ignored: none     

All files » src/operator/ » mapTo.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  1             1 22     1       1 22     1 22   1   1       1 22 22     1 35   1  
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
 
/**
 * Maps every value to the same value every time.
 * @param {any} value the value to map each incoming value to
 * @returns {Observable} an observable of the passed value that emits everytime the source does
 */
export function mapTo<T, R>(value: R) {
  return this.lift(new MapToOperator(value));
}
 
class MapToOperator<T, R> implements Operator<T, R> {
 
  value: R;
 
  constructor(value: R) {
    this.value = value;
  }
 
  call(subscriber: Subscriber<R>): Subscriber<T> {
    return new MapToSubscriber(subscriber, this.value);
  }
}
 
class MapToSubscriber<T, R> extends Subscriber<T> {
 
  value: R;
 
  constructor(destination: Subscriber<R>, value: R) {
    super(destination);
    this.value = value;
  }
 
  _next(x) {
    this.destination.next(this.value);
  }
}