rxjs

发布时间 2023-04-02 22:30:05作者: 平凡人就做平凡事

 安装

1. web:  https://unpkg.com/rxjs@7.8.0/dist/cjs/index.js

2. npm:  npm install rxjs 

github仓库: https://github.com/ReactiveX/rxjs

码云: https://gitee.com/mirrors/rxjs?_from=gitee_search

在webpack中使用: tsconfig.json 中需要配置  "moduleResolution": "node",  否则会报错找不到模块rxjs

在纯粹的typescript中,也需要tsconfig.json 中需要配置  "moduleResolution": "node",  但是虽然不报错,但编译后的js文件却不能正常运行,因为依赖的rxjs代码没有进行打包。

基本使用

 1 import { Observable } from "rxjs";
 2 
 3 const source$ = new Observable(observer => {
 4     console.log('start!');
 5     observer.next(1);
 6     observer.next(2);
 7     observer.complete();
 8     // observer.error({err: 'err'});
 9     return {
10         unsubscribe: () => {
11             console.log('unsubscribe');
12         }
13     }
14 });
15 const subscription = source$.subscribe({
16     next: val => console.log('val=', val),
17     error: err => console.log('err=', err),
18     complete: () => console.log('complete='),
19 });
20 subscription.unsubscribe();

 

end