Front end of the Slack clone application.

do.js 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /** PURE_IMPORTS_START .._operators_tap PURE_IMPORTS_END */
  2. import { tap as higherOrder } from '../operators/tap';
  3. /* tslint:enable:max-line-length */
  4. /**
  5. * Perform a side effect for every emission on the source Observable, but return
  6. * an Observable that is identical to the source.
  7. *
  8. * <span class="informal">Intercepts each emission on the source and runs a
  9. * function, but returns an output which is identical to the source as long as errors don't occur.</span>
  10. *
  11. * <img src="./img/do.png" width="100%">
  12. *
  13. * Returns a mirrored Observable of the source Observable, but modified so that
  14. * the provided Observer is called to perform a side effect for every value,
  15. * error, and completion emitted by the source. Any errors that are thrown in
  16. * the aforementioned Observer or handlers are safely sent down the error path
  17. * of the output Observable.
  18. *
  19. * This operator is useful for debugging your Observables for the correct values
  20. * or performing other side effects.
  21. *
  22. * Note: this is different to a `subscribe` on the Observable. If the Observable
  23. * returned by `do` is not subscribed, the side effects specified by the
  24. * Observer will never happen. `do` therefore simply spies on existing
  25. * execution, it does not trigger an execution to happen like `subscribe` does.
  26. *
  27. * @example <caption>Map every click to the clientX position of that click, while also logging the click event</caption>
  28. * var clicks = Rx.Observable.fromEvent(document, 'click');
  29. * var positions = clicks
  30. * .do(ev => console.log(ev))
  31. * .map(ev => ev.clientX);
  32. * positions.subscribe(x => console.log(x));
  33. *
  34. * @see {@link map}
  35. * @see {@link subscribe}
  36. *
  37. * @param {Observer|function} [nextOrObserver] A normal Observer object or a
  38. * callback for `next`.
  39. * @param {function} [error] Callback for errors in the source.
  40. * @param {function} [complete] Callback for the completion of the source.
  41. * @return {Observable} An Observable identical to the source, but runs the
  42. * specified Observer or callback(s) for each item.
  43. * @method do
  44. * @name do
  45. * @owner Observable
  46. */
  47. export function _do(nextOrObserver, error, complete) {
  48. return higherOrder(nextOrObserver, error, complete)(this);
  49. }
  50. //# sourceMappingURL=do.js.map