materialize.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var operators_1 = require("rxjs/operators");
  4. /**
  5. * Represents all of the notifications from the source Observable as `next`
  6. * emissions marked with their original types within {@link Notification}
  7. * objects.
  8. *
  9. * <span class="informal">Wraps `next`, `error` and `complete` emissions in
  10. * {@link Notification} objects, emitted as `next` on the output Observable.
  11. * </span>
  12. *
  13. * <img src="./img/materialize.png" width="100%">
  14. *
  15. * `materialize` returns an Observable that emits a `next` notification for each
  16. * `next`, `error`, or `complete` emission of the source Observable. When the
  17. * source Observable emits `complete`, the output Observable will emit `next` as
  18. * a Notification of type "complete", and then it will emit `complete` as well.
  19. * When the source Observable emits `error`, the output will emit `next` as a
  20. * Notification of type "error", and then `complete`.
  21. *
  22. * This operator is useful for producing metadata of the source Observable, to
  23. * be consumed as `next` emissions. Use it in conjunction with
  24. * {@link dematerialize}.
  25. *
  26. * @example <caption>Convert a faulty Observable to an Observable of Notifications</caption>
  27. * var letters = Rx.Observable.of('a', 'b', 13, 'd');
  28. * var upperCase = letters.map(x => x.toUpperCase());
  29. * var materialized = upperCase.materialize();
  30. * materialized.subscribe(x => console.log(x));
  31. *
  32. * // Results in the following:
  33. * // - Notification {kind: "N", value: "A", error: undefined, hasValue: true}
  34. * // - Notification {kind: "N", value: "B", error: undefined, hasValue: true}
  35. * // - Notification {kind: "E", value: undefined, error: TypeError:
  36. * // x.toUpperCase is not a function at MapSubscriber.letters.map.x
  37. * // [as project] (http://1…, hasValue: false}
  38. *
  39. * @see {@link Notification}
  40. * @see {@link dematerialize}
  41. *
  42. * @return {Observable<Notification<T>>} An Observable that emits
  43. * {@link Notification} objects that wrap the original emissions from the source
  44. * Observable with metadata.
  45. * @method materialize
  46. * @owner Observable
  47. */
  48. function materialize() {
  49. return operators_1.materialize()(this);
  50. }
  51. exports.materialize = materialize;
  52. //# sourceMappingURL=materialize.js.map