source: trip-planner-front/node_modules/rxjs/src/internal/operators/dematerialize.ts

Last change on this file was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.6 KB
Line 
1import { Operator } from '../Operator';
2import { Observable } from '../Observable';
3import { Subscriber } from '../Subscriber';
4import { Notification } from '../Notification';
5import { OperatorFunction } from '../types';
6
7/**
8 * Converts an Observable of {@link Notification} objects into the emissions
9 * that they represent.
10 *
11 * <span class="informal">Unwraps {@link Notification} objects as actual `next`,
12 * `error` and `complete` emissions. The opposite of {@link materialize}.</span>
13 *
14 * ![](dematerialize.png)
15 *
16 * `dematerialize` is assumed to operate an Observable that only emits
17 * {@link Notification} objects as `next` emissions, and does not emit any
18 * `error`. Such Observable is the output of a `materialize` operation. Those
19 * notifications are then unwrapped using the metadata they contain, and emitted
20 * as `next`, `error`, and `complete` on the output Observable.
21 *
22 * Use this operator in conjunction with {@link materialize}.
23 *
24 * ## Example
25 * Convert an Observable of Notifications to an actual Observable
26 * ```ts
27 * import { of, Notification } from 'rxjs';
28 * import { dematerialize } from 'rxjs/operators';
29 *
30 * const notifA = new Notification('N', 'A');
31 * const notifB = new Notification('N', 'B');
32 * const notifE = new Notification('E', undefined,
33 * new TypeError('x.toUpperCase is not a function')
34 * );
35 * const materialized = of(notifA, notifB, notifE);
36 * const upperCase = materialized.pipe(dematerialize());
37 * upperCase.subscribe(x => console.log(x), e => console.error(e));
38 *
39 * // Results in:
40 * // A
41 * // B
42 * // TypeError: x.toUpperCase is not a function
43 * ```
44 *
45 * @see {@link Notification}
46 * @see {@link materialize}
47 *
48 * @return {Observable} An Observable that emits items and notifications
49 * embedded in Notification objects emitted by the source Observable.
50 * @method dematerialize
51 * @owner Observable
52 */
53export function dematerialize<T>(): OperatorFunction<Notification<T>, T> {
54 return function dematerializeOperatorFunction(source: Observable<Notification<T>>) {
55 return source.lift(new DeMaterializeOperator());
56 };
57}
58
59class DeMaterializeOperator<T extends Notification<any>, R> implements Operator<T, R> {
60 call(subscriber: Subscriber<any>, source: any): any {
61 return source.subscribe(new DeMaterializeSubscriber(subscriber));
62 }
63}
64
65/**
66 * We need this JSDoc comment for affecting ESDoc.
67 * @ignore
68 * @extends {Ignored}
69 */
70class DeMaterializeSubscriber<T extends Notification<any>> extends Subscriber<T> {
71 constructor(destination: Subscriber<any>) {
72 super(destination);
73 }
74
75 protected _next(value: T) {
76 value.observe(this.destination);
77 }
78}
Note: See TracBrowser for help on using the repository browser.