W3cubDocs

/RxJS

Notification

class stable

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

class Notification<T> {
  static createNext<T>(value: T): Notification<T>
  static createError<T>(err?: any): Notification<T>
  static createComplete(): Notification<any>
  constructor(kind: 'N' | 'E' | 'C', value?: T, error?: any)
  hasValue: boolean
  kind: 'N' | 'E' | 'C'
  value?: T
  error?: any
  observe(observer: PartialObserver<T>): any
  do(next: (value: T) => void, error?: (err: any) => void, complete?: () => void): any
  accept(nextOrObserver: PartialObserver<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): Notification<T>

Parameters

value

The next value.

Returns

Notification<T>: The "next" Notification representing the argument.

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

static createError<T>(err?: any): Notification<T>

Parameters

err

Optional. Default is undefined.

The error error.

Returns

Notification<T>: The "error" Notification representing the argument.

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

static createComplete(): Notification<any>

Parameters

There are no parameters.

Returns

Notification<any>: The valueless "complete" Notification.

Constructor

constructor(kind: 'N' | 'E' | 'C', value?: T, error?: any)

Parameters

kind

Type: 'N' | 'E' | 'C'.

value

Optional. Default is undefined.

Type: T.

error

Optional. Default is undefined.

Type: any.

Properties

Property Type Description
hasValue boolean
kind 'N' | 'E' | 'C' Declared in constructor.
value T Declared in constructor.
error any Declared in constructor.

Methods

observe(observer: PartialObserver<T>): any

Delivers to the given observer the value wrapped by this Notification.

Parameters

observer

Type: PartialObserver.

Returns

any:

do(next: (value: T) => void, error?: (err: any) => void, complete?: () => void): any

Given some Observer callbacks, deliver the value represented by the current Notification to the correctly corresponding callback.

Parameters

next

An Observer next callback.

error

Optional. Default is undefined.

An Observer error callback.

complete

Optional. Default is undefined.

An Observer complete callback.

Returns

any:

accept(nextOrObserver: PartialObserver<T> | ((value: T) => void), error?: (err: any) => void, complete?: () => void)

Takes an Observer or its individual callback functions, and calls observe or do methods accordingly.

Parameters

nextOrObserver

An Observer or the next callback.

error

Optional. Default is undefined.

An Observer error callback.

complete

Optional. Default is undefined.

An Observer complete callback.

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–2018 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