标签:alpha active subject 空间 rom global log === activex
通常我们学习某个js库的功能时,我们会直接在html中用script引入该js库来写一些demo。笔者在学习rxjs时,用script标签引入时,就掉到了坑里。
从6.0.0-alpha.4版本起,(目前版本为6.3.0)全局命名空间为rxjs,使用方法如下:
<script src="https://cdn.bootcss.com/rxjs/6.0.0-alpha.4/rxjs.umd.js"></script>
<script>
/*
* https://github.com/ReactiveX/rxjs
* The global namespace for rxjs is rxjs
*/
const { Observable, Subject, ReplaySubject, from, of, range } = rxjs;
const { map, filter, switchMap } = rxjs.operators;
range(1, 200)
.pipe(
filter(x => x % 2 === 1),
map(x => x + x)
)
.subscribe(x => console.log(x));
</script>
而6.0.0-alpha.4版本以前(截至6.0.0-alpha.3),全局命名空间为Rx,使用示例:
<script src="https://cdn.bootcss.com/rxjs/6.0.0-alpha.3/Rx.min.js"></script>
var observable = Rx.Observable.interval(1000);
var subscription = observable.subscribe(x => console.log(x));
setTimeout(()=>{
subscription.unsubscribe();
},3000)
标签:alpha active subject 空间 rom global log === activex
原文地址:https://www.cnblogs.com/singeryoung/p/9567591.html