Rxjs 里 filter(Boolean) 的用法Rxjs 里 filter(Boolean) 的用法

简介: Rxjs 里 filter(Boolean) 的用法

StackOverflow 上的讨论:

ttps://stackoverflow.com/questions/53953015/using-rxjs-with-filterboolean-for-queries

一个例子:

image.png


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));

其实,这种写法等价于:


console.log(new Boolean("truthy")); // prints an object.
    console.log(new Boolean("truthy").valueOf() === true); // prints true
    console.log((new Boolean("truthy")) === true); // prints false
    console.log(Boolean("truthy") === true); // prints true

s false

   console.log(Boolean("truthy") === true); // prints true


相关文章
|
5月前
|
存储 JSON 算法
C++ JSON库 nlohmann::basic_json::boolean_t 的用法
C++ JSON库 nlohmann::basic_json::boolean_t 的用法
92 0
|
5月前
|
SQL 流计算 OceanBase
OceanBase CDC从热OB库采集过来的Tinyint(1)类型会默认转换成Boolean,请教一下,如果想转换成int类型,有什方法么?
【2月更文挑战第25天】OceanBase CDC从热OB库采集过来的Tinyint(1)类型会默认转换成Boolean,请教一下,如果想转换成int类型,有什方法么?
120 3
|
12月前
|
前端开发 JavaScript
前端基础 - JavaScript值Boolean类型的默认转换
前端基础 - JavaScript值Boolean类型的默认转换
56 0
|
2月前
|
Python
python布尔类型 (Boolean Type)
【8月更文挑战第3天】
42 8
|
2月前
|
Python
在Python中的Boolean类型
在Python中的Boolean类型
TS定义布尔值,let flag:boolean = true,定义数字类型 let a1:number = 10,赋值 let str1:string = ‘‘,打印c~.log($(str1))
TS定义布尔值,let flag:boolean = true,定义数字类型 let a1:number = 10,赋值 let str1:string = ‘‘,打印c~.log($(str1))
TS,数据类型概述,常见的基本数据类型有number/string/boolean/undefined/null,字符串用““,let food: string = ‘糖葫芦‘,布尔类型
TS,数据类型概述,常见的基本数据类型有number/string/boolean/undefined/null,字符串用““,let food: string = ‘糖葫芦‘,布尔类型
|
5月前
|
IDE Java 开发工具
阿里巴巴不建议 boolean 类型变量用 isXXX
阿里巴巴不建议 boolean 类型变量用 isXXX
52 1
|
5月前
|
算法 测试技术 编译器
【C++ 基本类型 bool 】深入探索C++中的布尔类型Boolean(二 )
【C++ 基本类型 bool 】深入探索C++中的布尔类型Boolean
110 0

热门文章

最新文章

下一篇
无影云桌面