首页 > Web开发 > 详细

rxjs全局命名空间

时间:2018-08-31 20:04:58      阅读:133      评论:0      收藏:0      [点我收藏+]

通常我们学习某个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)

rxjs全局命名空间

原文:https://www.cnblogs.com/singeryoung/p/9567591.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!