mapTo.js 1.2KB

123456789101112131415161718192021222324252627282930313233
  1. /** PURE_IMPORTS_START .._operators_mapTo PURE_IMPORTS_END */
  2. import { mapTo as higherOrder } from '../operators/mapTo';
  3. /**
  4. * Emits the given constant value on the output Observable every time the source
  5. * Observable emits a value.
  6. *
  7. * <span class="informal">Like {@link map}, but it maps every source value to
  8. * the same output value every time.</span>
  9. *
  10. * <img src="./img/mapTo.png" width="100%">
  11. *
  12. * Takes a constant `value` as argument, and emits that whenever the source
  13. * Observable emits a value. In other words, ignores the actual source value,
  14. * and simply uses the emission moment to know when to emit the given `value`.
  15. *
  16. * @example <caption>Map every click to the string 'Hi'</caption>
  17. * var clicks = Rx.Observable.fromEvent(document, 'click');
  18. * var greetings = clicks.mapTo('Hi');
  19. * greetings.subscribe(x => console.log(x));
  20. *
  21. * @see {@link map}
  22. *
  23. * @param {any} value The value to map each source value to.
  24. * @return {Observable} An Observable that emits the given `value` every time
  25. * the source Observable emits something.
  26. * @method mapTo
  27. * @owner Observable
  28. */
  29. export function mapTo(value) {
  30. return higherOrder(value)(this);
  31. }
  32. //# sourceMappingURL=mapTo.js.map