* 上的讨论:
https://*.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 true
console.log((new Boolean("truthy")) === true); // prints false
console.log(Boolean("truthy") === true); // prints true