Rx.Observer.create([onNext], [onError], [onCompleted])

Creates an observer from the specified onNext, onError, and onCompleted actions.

参数

  1. [onNext] (Function): Observer's onNext action implementation.
  2. [onError] (Function): Observer's onError action implementation.
  3. [onCompleted] (Function): Observer's onCompleted action implementation.

返回值

(Observer): The observer object implemented using the given actions.

Example

var source = Rx.Observable.return(42);

var observer = Rx.Observer.create(
  x => console.log(`onNext: ${x}`),
  e => console.log(`onError: ${e}`),
  () => console.log('onCompleted'));

var subscription = source.subscribe(observer);

// => onNext: 42
// => onCompleted