wishthis/node_modules/rxjs/internal/operators/materialize.d.ts

54 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-01-21 08:28:41 +00:00
import { Notification } from '../Notification';
2022-05-29 09:24:36 +00:00
import { OperatorFunction } from '../types';
2022-01-21 08:28:41 +00:00
/**
* Represents all of the notifications from the source Observable as `next`
* emissions marked with their original types within {@link Notification}
* objects.
*
* <span class="informal">Wraps `next`, `error` and `complete` emissions in
* {@link Notification} objects, emitted as `next` on the output Observable.
* </span>
*
* ![](materialize.png)
*
* `materialize` returns an Observable that emits a `next` notification for each
* `next`, `error`, or `complete` emission of the source Observable. When the
* source Observable emits `complete`, the output Observable will emit `next` as
* a Notification of type "complete", and then it will emit `complete` as well.
* When the source Observable emits `error`, the output will emit `next` as a
* Notification of type "error", and then `complete`.
*
* This operator is useful for producing metadata of the source Observable, to
* be consumed as `next` emissions. Use it in conjunction with
* {@link dematerialize}.
*
* ## Example
* Convert a faulty Observable to an Observable of Notifications
* ```ts
2022-05-29 09:24:36 +00:00
* import { of } from 'rxjs';
* import { materialize, map } from 'rxjs/operators';
2022-01-21 08:28:41 +00:00
*
* const letters = of('a', 'b', 13, 'd');
2022-05-29 09:24:36 +00:00
* const upperCase = letters.pipe(map(x => x.toUpperCase()));
2022-01-21 08:28:41 +00:00
* const materialized = upperCase.pipe(materialize());
* materialized.subscribe(x => console.log(x));
*
* // Results in the following:
2022-05-29 09:24:36 +00:00
* // - Notification {kind: "N", value: "A", error: undefined, hasValue: true}
* // - Notification {kind: "N", value: "B", error: undefined, hasValue: true}
* // - Notification {kind: "E", value: undefined, error: TypeError:
* // x.toUpperCase is not a function at MapSubscriber.letters.map.x
* // [as project] (http://1…, hasValue: false}
2022-01-21 08:28:41 +00:00
* ```
*
* @see {@link Notification}
* @see {@link dematerialize}
*
2022-05-29 09:24:36 +00:00
* @return {Observable<Notification<T>>} An Observable that emits
* {@link Notification} objects that wrap the original emissions from the source
* Observable with metadata.
* @method materialize
* @owner Observable
2022-01-21 08:28:41 +00:00
*/
2022-05-29 09:24:36 +00:00
export declare function materialize<T>(): OperatorFunction<T, Notification<T>>;