Front end of the Slack clone application.

mapTo.js 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /** PURE_IMPORTS_START .._Subscriber PURE_IMPORTS_END */
  2. var __extends = (this && this.__extends) || function (d, b) {
  3. for (var p in b)
  4. if (b.hasOwnProperty(p))
  5. d[p] = b[p];
  6. function __() { this.constructor = d; }
  7. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  8. };
  9. import { Subscriber } from '../Subscriber';
  10. /**
  11. * Emits the given constant value on the output Observable every time the source
  12. * Observable emits a value.
  13. *
  14. * <span class="informal">Like {@link map}, but it maps every source value to
  15. * the same output value every time.</span>
  16. *
  17. * <img src="./img/mapTo.png" width="100%">
  18. *
  19. * Takes a constant `value` as argument, and emits that whenever the source
  20. * Observable emits a value. In other words, ignores the actual source value,
  21. * and simply uses the emission moment to know when to emit the given `value`.
  22. *
  23. * @example <caption>Map every click to the string 'Hi'</caption>
  24. * var clicks = Rx.Observable.fromEvent(document, 'click');
  25. * var greetings = clicks.mapTo('Hi');
  26. * greetings.subscribe(x => console.log(x));
  27. *
  28. * @see {@link map}
  29. *
  30. * @param {any} value The value to map each source value to.
  31. * @return {Observable} An Observable that emits the given `value` every time
  32. * the source Observable emits something.
  33. * @method mapTo
  34. * @owner Observable
  35. */
  36. export function mapTo(value) {
  37. return function (source) { return source.lift(new MapToOperator(value)); };
  38. }
  39. var MapToOperator = /*@__PURE__*/ (/*@__PURE__*/ function () {
  40. function MapToOperator(value) {
  41. this.value = value;
  42. }
  43. MapToOperator.prototype.call = function (subscriber, source) {
  44. return source.subscribe(new MapToSubscriber(subscriber, this.value));
  45. };
  46. return MapToOperator;
  47. }());
  48. /**
  49. * We need this JSDoc comment for affecting ESDoc.
  50. * @ignore
  51. * @extends {Ignored}
  52. */
  53. var MapToSubscriber = /*@__PURE__*/ (/*@__PURE__*/ function (_super) {
  54. __extends(MapToSubscriber, _super);
  55. function MapToSubscriber(destination, value) {
  56. _super.call(this, destination);
  57. this.value = value;
  58. }
  59. MapToSubscriber.prototype._next = function (x) {
  60. this.destination.next(this.value);
  61. };
  62. return MapToSubscriber;
  63. }(Subscriber));
  64. //# sourceMappingURL=mapTo.js.map