RxJS 初学者,看到这个源码很想用用看,不过貌似是6版本一下的,操作符的语法不太一样 自己试着升级到6以上版本,不过没有出现逾期的效果,希望能帮忙升级到6以上版本 这里是连接:https://link.zhihu.com/?targe...
Rx6主要是操作符调用方式不一样,Rx6使用pipe(a, b, c)这种语法串联。 另外操作符不再是一个原型方法,而是一个单独的函数,比如这样子导入import { map, filter, scan } from 'rxjs/operators';, 这样就可以实现Tree-shaking了。 举个例子: Rx5 source .map(x => x + x) .mergeMap(n => of(n + 1, n + 2) .filter(x => x % 1 == 0) .scan((acc, x) => acc + x, 0) ) .catch(err => of('error found')) .subscribe(printResult); Rx6 source.pipe( // Observable有个pipe方法,用来组合操作符 map(x => x + x), mergeMap(n => of(n + 1, n + 2).pipe( filter(x => x % 1 == 0), scan((acc, x) => acc + x, 0), )), catchError(err => of('error found')), ).subscribe(printResult); 初学者建议官方文档,现在大部分中文文档都是基于Rx5的。详细见RxJS v5.x to v6 Update Guide
Rx6主要是操作符调用方式不一样,Rx6使用
pipe(a, b, c)
这种语法串联。另外操作符不再是一个原型方法,而是一个单独的函数,比如这样子导入
import { map, filter, scan } from 'rxjs/operators';
, 这样就可以实现Tree-shaking了。举个例子:
Rx5
Rx6
初学者建议官方文档,现在大部分中文文档都是基于Rx5的。
详细见RxJS v5.x to v6 Update Guide