分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

rxjs全局命名空间

发布时间:2023-09-06 02:12责任编辑:彭小芳关键词:js

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

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved