Skip to content

Latest commit

 

History

History
31 lines (26 loc) · 674 Bytes

Observer.md

File metadata and controls

31 lines (26 loc) · 674 Bytes

Observer

Observer是一个对象,用来做subscribe方法的参数,这个对象含有一个closed属性,以及next,error,complete三个方法

用法

const observer = {
  next: x => console.log('got value ' + x),
  error: err => console.error('something wrong occurred: ' + err),
  complete: () => console.log('done'),
};
observable.subscribe(observer); 

源码

export const empty: Observer<any> = {
  closed: true,
  next(value: any): void { /* noop */},
  error(err: any): void {
    if (config.useDeprecatedSynchronousErrorHandling) {
      throw err;
    } else {
      hostReportError(err);
    }
  },
  complete(): void { /*noop*/ }
};