获取可观察的RXJ内观察的价值

发布于 2025-02-12 04:56:49 字数 885 浏览 1 评论 0原文

我在字段属性中可观察到以下可观察到的

  config$: Observable<QueryBuilderConfig>;

this.config$.pipe(map(item => {
  return {
    fieldGroups: [
      { id: CustomAttributeEntityType.Risk, label: this.l('Risk') },
      { id: CustomAttributeEntityType.RiskAssessment, label: this.l('Risk Assessment') }
    ],
    fields: this.metricCreateConfigureStore.queryBuilderFields$, // Get the value from obserable
    allowEmptyRules: true,
    allowEmptyRulesets: false
  }
}));

属性,我想从另一个可观察的可观察的值中获取值,例如

 fields: this.metricCreateConfigureStore.queryBuilderFields$

querybuilderfields $ return observable 如下

readonly queryBuilderFields$: Observable<{ [key: string]: QueryBuilderFieldsDto }> = this.select(state => state.queryBuilderFields);

如何我可以获得价值,而无需在那儿订阅吗?

I have below Observable

  config$: Observable<QueryBuilderConfig>;

this.config$.pipe(map(item => {
  return {
    fieldGroups: [
      { id: CustomAttributeEntityType.Risk, label: this.l('Risk') },
      { id: CustomAttributeEntityType.RiskAssessment, label: this.l('Risk Assessment') }
    ],
    fields: this.metricCreateConfigureStore.queryBuilderFields$, // Get the value from obserable
    allowEmptyRules: true,
    allowEmptyRulesets: false
  }
}));

In the field attribute, I want to get the value from another observable, something like below

 fields: this.metricCreateConfigureStore.queryBuilderFields$

queryBuilderFields$ return Observable as below

readonly queryBuilderFields$: Observable<{ [key: string]: QueryBuilderFieldsDto }> = this.select(state => state.queryBuilderFields);

How can I get the value, without subscribe over there??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小梨窩很甜 2025-02-19 04:56:49

取决于您确切地含义的“来自其他可观察到的价值”的含义:两个流独立发射,您想从两者中捕获值吗?那就是

combineLatest([stream1$, stream2$])
    .subscribe(([val1$, val2$]) => //...

或使用一个流的值来创建另一个流?那是switchmap(或者也许是其兄弟姐妹之一,例如concatmapmergemap等):

stream1$.pipe(
    tap(/* maybe some side effects here */),
    switchMap(value1 => generateStream2(value1))
).subscribe(value2 => //...

Depends on what you exactly mean by "value from other observable": two streams emitting independently, and you want to catch values from both? That's

combineLatest([stream1$, stream2$])
    .subscribe(([val1$, val2$]) => //...

Or use value from one stream to create another one? That's switchMap (or maybe one of its siblings, like concatMap, mergeMap etc.):

stream1$.pipe(
    tap(/* maybe some side effects here */),
    switchMap(value1 => generateStream2(value1))
).subscribe(value2 => //...
烙印 2025-02-19 04:56:49

那将是类似的东西


this.metricCreateConfigureStore.queryBuilderFields$.pipe(
   switchMap((fields) => this.config$.pipe(
      map((item) => {
         return { ... use fields and item }
      })
   ))
)


,而且我不会在流操作中使用this.l()函数调用,而是要使用要使用的参数,所以纯粹的函数。

That would be something like


this.metricCreateConfigureStore.queryBuilderFields$.pipe(
   switchMap((fields) => this.config$.pipe(
      map((item) => {
         return { ... use fields and item }
      })
   ))
)


And also, I would not use this.l() function call inside the stream handlind, but put a parameter to be used, so pure function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文