反应重组componentFromStream更新不触发

时间:2018-09-30 09:21:44

标签: reactjs rxjs recompose

我有一个来自Observable的Rx interval和另一个来自于React prop的观察对象,我确实与withLatestFrom合并了两个Observables来监听更新并使用recompose渲染流组件工作正常,但问题是,当我将道具从local更改为utc时,它没有更新。

您可以尝试增加间隔并尝试更改LOCAL / UTC按钮,它不会触发,但仅在时间改变时才会更新。

working demo with code

const locale$ = prop$.pipe(p => p)
  const timeInterval$ = prop$.pipe(
    switchMap(({intervalTime}) => interval(intervalTime)),
    withLatestFrom(locale$, (b, c) => {
    return c.locale === 'local' ? moment().format('HH:mm:ss') : moment().utc().format('HH:mm:ss')
  })//.pipe(map(p => p))
  )

1 个答案:

答案 0 :(得分:0)

您要查找的是 combineLatest (不是 withLatestFrom )。

withLatestFrom

将源与另一个可观察到的(或更多!)组合成具有每个最新值的可观察到的发射数组,仅在源发射时

combineLatest

将多个可观察物组合成一个可观察物,该可观察物发出具有每个来源的最新值的数组,每当这些可观察物之一发出时,

这是CombineLatest的示例:

next