UNPKG

2.19 kBTypeScriptView Raw
1import { Notification } from '../Notification';
2import { OperatorFunction, ObservableNotification } from '../types';
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 * ![](materialize.png)
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
26 *
27 * Convert a faulty Observable to an Observable of Notifications
28 *
29 * ```ts
30 * import { of, materialize, map } from 'rxjs';
31 *
32 * const letters = of('a', 'b', 13, 'd');
33 * const upperCase = letters.pipe(map((x: any) => x.toUpperCase()));
34 * const materialized = upperCase.pipe(materialize());
35 *
36 * materialized.subscribe(x => console.log(x));
37 *
38 * // Results in the following:
39 * // - Notification { kind: 'N', value: 'A', error: undefined, hasValue: true }
40 * // - Notification { kind: 'N', value: 'B', error: undefined, hasValue: true }
41 * // - Notification { kind: 'E', value: undefined, error: TypeError { message: x.toUpperCase is not a function }, hasValue: false }
42 * ```
43 *
44 * @see {@link Notification}
45 * @see {@link dematerialize}
46 *
47 * @return A function that returns an Observable that emits
48 * {@link Notification} objects that wrap the original emissions from the
49 * source Observable with metadata.
50 */
51export declare function materialize<T>(): OperatorFunction<T, Notification<T> & ObservableNotification<T>>;
52//# sourceMappingURL=materialize.d.ts.map
\No newline at end of file