UNPKG

3.32 kBTypeScriptView Raw
1import { PartialObserver } from './types';
2import { Observable } from './Observable';
3export declare const enum NotificationKind {
4 NEXT = "N",
5 ERROR = "E",
6 COMPLETE = "C"
7}
8/**
9 * Represents a push-based event or value that an {@link Observable} can emit.
10 * This class is particularly useful for operators that manage notifications,
11 * like {@link materialize}, {@link dematerialize}, {@link observeOn}, and
12 * others. Besides wrapping the actual delivered value, it also annotates it
13 * with metadata of, for instance, what type of push message it is (`next`,
14 * `error`, or `complete`).
15 *
16 * @see {@link materialize}
17 * @see {@link dematerialize}
18 * @see {@link observeOn}
19 *
20 * @class Notification<T>
21 */
22export declare class Notification<T> {
23 kind: NotificationKind;
24 value?: T;
25 error?: any;
26 hasValue: boolean;
27 constructor(kind: NotificationKind, value?: T, error?: any);
28 /**
29 * Delivers to the given `observer` the value wrapped by this Notification.
30 * @param {Observer} observer
31 * @return
32 */
33 observe(observer: PartialObserver<T>): any;
34 /**
35 * Given some {@link Observer} callbacks, deliver the value represented by the
36 * current Notification to the correctly corresponding callback.
37 * @param {function(value: T): void} next An Observer `next` callback.
38 * @param {function(err: any): void} [error] An Observer `error` callback.
39 * @param {function(): void} [complete] An Observer `complete` callback.
40 * @return {any}
41 */
42 do(next: (value: T) => void, error?: (err: any) => void, complete?: () => void): any;
43 /**
44 * Takes an Observer or its individual callback functions, and calls `observe`
45 * or `do` methods accordingly.
46 * @param {Observer|function(value: T): void} nextOrObserver An Observer or
47 * the `next` callback.
48 * @param {function(err: any): void} [error] An Observer `error` callback.
49 * @param {function(): void} [complete] An Observer `complete` callback.
50 * @return {any}
51 */
52 accept(nextOrObserver: PartialObserver<T> | ((value: T) => void), error?: (err: any) => void, complete?: () => void): any;
53 /**
54 * Returns a simple Observable that just delivers the notification represented
55 * by this Notification instance.
56 * @return {any}
57 */
58 toObservable(): Observable<T>;
59 private static completeNotification;
60 private static undefinedValueNotification;
61 /**
62 * A shortcut to create a Notification instance of the type `next` from a
63 * given value.
64 * @param {T} value The `next` value.
65 * @return {Notification<T>} The "next" Notification representing the
66 * argument.
67 * @nocollapse
68 */
69 static createNext<T>(value: T): Notification<T>;
70 /**
71 * A shortcut to create a Notification instance of the type `error` from a
72 * given error.
73 * @param {any} [err] The `error` error.
74 * @return {Notification<T>} The "error" Notification representing the
75 * argument.
76 * @nocollapse
77 */
78 static createError<T>(err?: any): Notification<T>;
79 /**
80 * A shortcut to create a Notification instance of the type `complete`.
81 * @return {Notification<any>} The valueless "complete" Notification.
82 * @nocollapse
83 */
84 static createComplete(): Notification<any>;
85}