Notification
class
deprecated
Represents a push-based event or value that an Observable
can emit. This class is particularly useful for operators that manage notifications, like materialize
, dematerialize
, observeOn
, and others. Besides wrapping the actual delivered value, it also annotates it with metadata of, for instance, what type of push message it is (next
, error
, or complete
).
Deprecation Notes
It is NOT recommended to create instances of Notification
directly. Rather, try to create POJOs matching the signature outlined in ObservableNotification
. For example: { kind: 'N', value: 1 }
, { kind: 'E', error: new Error('bad') }
, or { kind: 'C' }
. Will be removed in v8.
class Notification<T> { static createNext<T>(value: T) static createError(err?: any) static createComplete(): Notification<never> & CompleteNotification constructor(kind: "N" | "E" | "C", value?: T, error?: any) get hasValue: boolean get kind: 'N' | 'E' | 'C' get value?: T get error?: any observe(observer: PartialObserver<T>): void do(nextHandler: (value: T) => void, errorHandler?: (err: any) => void, completeHandler?: () => void): void accept(nextOrObserver: NextObserver<T> | ErrorObserver<T> | CompletionObserver<T> | ((value: T) => void), error?: (err: any) => void, complete?: () => void) toObservable(): Observable<T> }
Static Methods
A shortcut to create a Notification instance of the type next
from a given value.
static createNext<T>(value: T)
Deprecation Notes
It is NOT recommended to create instances of Notification
directly. Rather, try to create POJOs matching the signature outlined in ObservableNotification
. For example: { kind: 'N', value: 1 }
, { kind: 'E', error: new Error('bad') }
, or { kind: 'C' }
. Will be removed in v8.
Parameters
value | The |
A shortcut to create a Notification instance of the type error
from a given error.
static createError(err?: any)
Deprecation Notes
It is NOT recommended to create instances of Notification
directly. Rather, try to create POJOs matching the signature outlined in ObservableNotification
. For example: { kind: 'N', value: 1 }
, { kind: 'E', error: new Error('bad') }
, or { kind: 'C' }
. Will be removed in v8.
Parameters
err | Optional. Default is The |
A shortcut to create a Notification instance of the type complete
.
static createComplete(): Notification<never> & CompleteNotification
Deprecation Notes
It is NOT recommended to create instances of Notification
directly. Rather, try to create POJOs matching the signature outlined in ObservableNotification
. For example: { kind: 'N', value: 1 }
, { kind: 'E', error: new Error('bad') }
, or { kind: 'C' }
. Will be removed in v8.
Parameters
There are no parameters.
Returns
Notification<never> & CompleteNotification
: The valueless "complete" Notification.
Constructor
constructor(kind: "N", value?: T)
Creates a "Next" notification object.
Deprecation Notes
Internal implementation detail. Use createNext instead.
Parameters
kind | Always |
value | Optional. Default is The value to notify with if observed. |
constructor(kind: "E", value: undefined, error: any)
Creates an "Error" notification object.
Deprecation Notes
Internal implementation detail. Use createError instead.
Parameters
kind | Always |
value | Always |
error | The error to notify with if observed. |
constructor(kind: "C")
Creates a "completion" notification object.
Deprecation Notes
Internal implementation detail. Use createComplete instead.
Parameters
kind | Always |
Properties
Property | Type | Description |
---|---|---|
hasValue
| boolean |
Read-only. A value signifying that the notification will "next" if observed. In truth, This is really synonymous with just checking |
kind
| 'N' | 'E' | 'C' | Read-only. Declared in constructor. |
value
| T | Read-only. Declared in constructor. |
error
| any | Read-only. Declared in constructor. |
Methods
observe(observer: PartialObserver<T>): void
Executes the appropriate handler on a passed observer
given the kind
of notification. If the handler is missing it will do nothing. Even if the notification is an error, if there is no error handler on the observer, an error will not be thrown, it will noop.
Parameters
observer | The observer to notify. |
Returns
void
do(next: (value: T) => void, error: (err: any) => void, complete: () => void): void
Executes a notification on the appropriate handler from a list provided. If a handler is missing for the kind of notification, nothing is called and no error is thrown, it will be a noop.
Deprecation Notes
Replaced with observe. Will be removed in v8.
Parameters
next | A next handler |
error | An error handler |
complete | A complete handler |
Returns
void
do(next: (value: T) => void, error: (err: any) => void): void
Executes a notification on the appropriate handler from a list provided. If a handler is missing for the kind of notification, nothing is called and no error is thrown, it will be a noop.
Deprecation Notes
Replaced with observe. Will be removed in v8.
Parameters
next | A next handler |
error | An error handler |
Returns
void
do(next: (value: T) => void): void
Executes the next handler if the Notification is of kind
"N"
. Otherwise this will not error, and it will be a noop.
Deprecation Notes
Replaced with observe. Will be removed in v8.
Parameters
next | The next handler |
Returns
void
accept(next: (value: T) => void, error: (err: any) => void, complete: () => void): void
Executes a notification on the appropriate handler from a list provided. If a handler is missing for the kind of notification, nothing is called and no error is thrown, it will be a noop.
Deprecation Notes
Replaced with observe. Will be removed in v8.
Parameters
next | A next handler |
error | An error handler |
complete | A complete handler |
Returns
void
accept(next: (value: T) => void, error: (err: any) => void): void
Executes a notification on the appropriate handler from a list provided. If a handler is missing for the kind of notification, nothing is called and no error is thrown, it will be a noop.
Deprecation Notes
Replaced with observe. Will be removed in v8.
Parameters
next | A next handler |
error | An error handler |
Returns
void
accept(next: (value: T) => void): void
Executes the next handler if the Notification is of kind
"N"
. Otherwise this will not error, and it will be a noop.
Deprecation Notes
Replaced with observe. Will be removed in v8.
Parameters
next | The next handler |
Returns
void
accept(observer: PartialObserver<T>): void
Executes the appropriate handler on a passed observer
given the kind
of notification. If the handler is missing it will do nothing. Even if the notification is an error, if there is no error handler on the observer, an error will not be thrown, it will noop.
Deprecation Notes
Replaced with observe. Will be removed in v8.
Parameters
observer | The observer to notify. |
Returns
void
toObservable(): Observable<T>
Returns a simple Observable that just delivers the notification represented by this Notification instance.
Deprecation Notes
Will be removed in v8. To convert a Notification
to an Observable
, use of
and dematerialize
: of(notification).pipe(dematerialize())
.
Parameters
There are no parameters.
Returns
Observable<T>
See Also
© 2015–2021 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/index/class/Notification