Rxjs 里 filter(Boolean) 的用法
StackOverflow 上的讨论:
https://stackoverflow.com/questions/53953015/using-rxjs-with-filterboolean-for-queries
一个例子:
const result$ = events.get(CartAddEntrySuccessEvent).pipe(// When the above event is captured, wait for the cart to be stable// (because OCC reloads the cart after any cart operation)...switchMap((event) =>cartService.isStable().pipe(filter(Boolean), mapTo(event))),// Merge the state snapshot of the cart with the data from the event:withLatestFrom(cartService.getActive()),map(([event, cart]) => ({ ...event, cart })));result$.subscribe((data) => console.log('Jerry', data));
其实,这种写法等价于:
filter(v=>!!v)
The Boolean global reference points to the constructor function which returns a boolean value from the first argument.
The constructor can be used to create a boolean wrapper object, but it is not the same as the primitive true value.
console.log(new Boolean("truthy")); // prints an object.console.log(new Boolean("truthy").valueOf() === true); // prints trueconsole.log((new Boolean("truthy")) === true); // prints falseconsole.log(Boolean("truthy") === true); // prints true
Rxjs 里 filter(Boolean) 的用法相关推荐
- rxjs里switchMap operators的用法
switchMap相关文章 rxjs里switchMap operators的用法 通过rxjs的一个例子, 来学习SwitchMap的使用方法 rxjs switchMap的实现原理 rxjs的ma ...
- rxjs里concatMap operators的用法
Projects each source value to an Observable which is merged in the output Observable, in a serialize ...
- rxjs里delay operators的用法
Delays the emission of items from the source Observable by a given timeout or until a given Date. 例子 ...
- rxjs里debounceTime operators的用法
Emits a value from the source Observable only after a particular time span has passed without anothe ...
- rxjs里withLatestFrom operators的用法
Combines the source Observable with other Observables to create an Observable whose values are calcu ...
- rxjs里combineLatest operators的用法
Whenever any input Observable emits a value, it computes a formula using the latest values from all ...
- rxjs里scan operators的用法
Applies an accumulator function over the source Observable, and returns each intermediate result, wi ...
- rxjs里mapTo operators的用法
和map工作原理类似,只不过emit的是一个常数. Like map, but it maps every source value to the same output value every ti ...
- rxjs里merge operators的用法
stream是lazy的,no subscription, no calculation occurs. 作用:Flattens multiple Observables together by bl ...
最新文章
- python培训班学费-南京Python培训班学费贵吗怎么收费
- 第三次学JAVA再学不好就吃翔(part57)--StringBuffer和String的相互转换
- 定时插座动一下就断_使用插座定时器在某些时候自动将您的Amazon Echo静音
- 车牌识别之车牌定位(方案总结)
- 飞鸽传书不能传送文件
- [COURSE_PTHE] 18. 缓冲区溢出
- android elf 加固_APK一键自动化加固脚本
- 中国的就业(人才)市场缺什么?
- 做数据中心,腾讯是认真的!
- gdb 调试 入手 实例讲解-转
- mysql5.7 yum 密码,CentOS 7.7解决yum方式安装的MySQL 5.7 root用户密码丢失问题
- qregularexpression和qregexp的区别
- lol官网服务器维修啥意思,英雄联盟5.6维护 lol官网服务器维护公告
- 三极管的下拉电阻作用是什么?
- JIAR安装报错IRA Startup Failed
- 移动端二三事【五】:陀螺仪(重力感应器)实现手机位置、加速度感应以及常见应用。
- php拼接全景图,Opencv使用Stitcher类图像拼接生成全景图像
- 无需再怨恨“刘海屏”了,因为适配十分简单
- C语言初学基础篇:No such file or directory 报错 ( C-Free 5 软件使用 )
- 同时安装wampserver和xampp