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) 的用法相关推荐

  1. rxjs里switchMap operators的用法

    switchMap相关文章 rxjs里switchMap operators的用法 通过rxjs的一个例子, 来学习SwitchMap的使用方法 rxjs switchMap的实现原理 rxjs的ma ...

  2. rxjs里concatMap operators的用法

    Projects each source value to an Observable which is merged in the output Observable, in a serialize ...

  3. rxjs里delay operators的用法

    Delays the emission of items from the source Observable by a given timeout or until a given Date. 例子 ...

  4. rxjs里debounceTime operators的用法

    Emits a value from the source Observable only after a particular time span has passed without anothe ...

  5. rxjs里withLatestFrom operators的用法

    Combines the source Observable with other Observables to create an Observable whose values are calcu ...

  6. rxjs里combineLatest operators的用法

    Whenever any input Observable emits a value, it computes a formula using the latest values from all ...

  7. rxjs里scan operators的用法

    Applies an accumulator function over the source Observable, and returns each intermediate result, wi ...

  8. rxjs里mapTo operators的用法

    和map工作原理类似,只不过emit的是一个常数. Like map, but it maps every source value to the same output value every ti ...

  9. rxjs里merge operators的用法

    stream是lazy的,no subscription, no calculation occurs. 作用:Flattens multiple Observables together by bl ...

最新文章

  1. python培训班学费-南京Python培训班学费贵吗怎么收费
  2. 第三次学JAVA再学不好就吃翔(part57)--StringBuffer和String的相互转换
  3. 定时插座动一下就断_使用插座定时器在某些时候自动将您的Amazon Echo静音
  4. 车牌识别之车牌定位(方案总结)
  5. 飞鸽传书不能传送文件
  6. [COURSE_PTHE] 18. 缓冲区溢出
  7. android elf 加固_APK一键自动化加固脚本
  8. 中国的就业(人才)市场缺什么?
  9. 做数据中心,腾讯是认真的!
  10. gdb 调试 入手 实例讲解-转
  11. mysql5.7 yum 密码,CentOS 7.7解决yum方式安装的MySQL 5.7 root用户密码丢失问题
  12. qregularexpression和qregexp的区别
  13. lol官网服务器维修啥意思,英雄联盟5.6维护 lol官网服务器维护公告
  14. 三极管的下拉电阻作用是什么?
  15. JIAR安装报错IRA Startup Failed
  16. 移动端二三事【五】:陀螺仪(重力感应器)实现手机位置、加速度感应以及常见应用。
  17. php拼接全景图,Opencv使用Stitcher类图像拼接生成全景图像
  18. 无需再怨恨“刘海屏”了,因为适配十分简单
  19. C语言初学基础篇:No such file or directory 报错 ( C-Free 5 软件使用 )
  20. 同时安装wampserver和xampp

热门文章

  1. “chaos“的算法--之双向链表
  2. 抵御物联网DDoS军团
  3. C# asp:Repeater DataSource ListT
  4. Linux 查看CPU信息、机器型号等硬件信息
  5. qq邮箱使用outlook 2007
  6. DHCP***的防御处理总结
  7. Web三个域对象的区别
  8. 整理-----内置函数
  9. mysql ERROR 1045 (28000): 错误解决办法
  10. 移动端效果之Picker