materialize.d.ts 2.1 KB

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