从流中获取第一个定义值并在 RxJS 中取消订阅的最佳方法是什么?
WHat's the best way to take a first defined value from a stream and unsubscribe in RxJS?
我有以下代码:
this.type$.pipe(
filter(val => !!val), // skip initial undefined value
take(1), // unsubscribe after geting the first defined value
map((type) => {
this.store.dispatch(new LoadForms(type.schemaUid));
})
).subscribe();
这是我在我的应用程序的几个地方使用的模式。有没有办法通过使用任何更智能的 RxJS 运算符来缩短它?它应该只接受定义的值,然后立即取消订阅。
使用single()
this.type$.pipe(
filter(val => !!val),
single()
或带过滤功能
this.type$.pipe(
first(val => !!val),...
我有以下代码:
this.type$.pipe(
filter(val => !!val), // skip initial undefined value
take(1), // unsubscribe after geting the first defined value
map((type) => {
this.store.dispatch(new LoadForms(type.schemaUid));
})
).subscribe();
这是我在我的应用程序的几个地方使用的模式。有没有办法通过使用任何更智能的 RxJS 运算符来缩短它?它应该只接受定义的值,然后立即取消订阅。
使用single()
this.type$.pipe(
filter(val => !!val),
single()
或带过滤功能
this.type$.pipe(
first(val => !!val),...