rxjs / 7.5.5 / api / index / class / notification.html /

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)

Parameters

value T

The next value.

A shortcut to create a Notification instance of the type error from a given error.

static createError(err?: any)

Parameters

err any

Optional. Default is undefined.

The error error.

A shortcut to create a Notification instance of the type complete.

static createComplete(): Notification<never> & CompleteNotification

Parameters

There are no parameters.

Returns

Notification<never> & CompleteNotification: The valueless "complete" Notification.

Constructor

constructor(kind: "N", value?: T)

Creates a "Next" notification object.

Parameters

kind "N"

Always 'N'

value T

Optional. Default is undefined.

The value to notify with if observed.

constructor(kind: "E", value: undefined, error: any)

Creates an "Error" notification object.

Parameters

kind "E"

Always 'E'

value undefined

Always undefined

error any

The error to notify with if observed.

constructor(kind: "C")

Creates a "completion" notification object.

Parameters

kind "C"

Always 'C'

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".

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 PartialObserver<T>

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.

Parameters

next (value: T) => void

A next handler

error (err: any) => void

An error handler

complete () => void

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.

Parameters

next (value: T) => void

A next handler

error (err: any) => void

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.

Parameters

next (value: T) => void

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.

Parameters

next (value: T) => void

A next handler

error (err: any) => void

An error handler

complete () => void

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.

Parameters

next (value: T) => void

A next handler

error (err: any) => void

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.

Parameters

next (value: T) => void

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.

Parameters

observer PartialObserver<T>

The observer to notify.

Returns

void

toObservable(): Observable<T>

Returns a simple Observable that just delivers the notification represented by this Notification instance.

Parameters

There are no parameters.

Returns

Observable<T>

See Also

© 2015–2022 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