map.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Applies a given `project` function to each value emitted by the source
  6. * Observable, and emits the resulting values as an Observable.
  7. *
  8. * <span class="informal">Like [Array.prototype.map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map),
  9. * it passes each source value through a transformation function to get
  10. * corresponding output values.</span>
  11. *
  12. * <img src="./img/map.png" width="100%">
  13. *
  14. * Similar to the well known `Array.prototype.map` function, this operator
  15. * applies a projection to each value and emits that projection in the output
  16. * Observable.
  17. *
  18. * @example <caption>Map every click to the clientX position of that click</caption>
  19. * var clicks = Rx.Observable.fromEvent(document, 'click');
  20. * var positions = clicks.map(ev => ev.clientX);
  21. * positions.subscribe(x => console.log(x));
  22. *
  23. * @see {@link mapTo}
  24. * @see {@link pluck}
  25. *
  26. * @param {function(value: T, index: number): R} project The function to apply
  27. * to each `value` emitted by the source Observable. The `index` parameter is
  28. * the number `i` for the i-th emission that has happened since the
  29. * subscription, starting from the number `0`.
  30. * @param {any} [thisArg] An optional argument to define what `this` is in the
  31. * `project` function.
  32. * @return {Observable<R>} An Observable that emits the values from the source
  33. * Observable transformed by the given `project` function.
  34. * @method map
  35. * @owner Observable
  36. */
  37. function map(project, thisArg) {
  38. return operators_1.map(project, thisArg)(this);
  39. }
  40. exports.map = map;
  41. //# sourceMappingURL=map.js.map