简体   繁体   English

反应重组componentFromStream更新不触发

[英]React recompose componentFromStream update not triggers

I have Rx Observable from interval and another observable from react prop, I did merge with withLatestFrom both Observables to listen update and render stream component with recompose , its working fine but issue is its not updating when i change the prop to local to utc . 我有interval Rx Observable和react prop的另一个Observable ,我的确与withLatestFrom和Observables合并了,以侦听更新并通过recompose渲染流组件,其工作正常,但问题是当我将prop更改为localutc时它没有更新。

You can try with increase interval and try to change the LOCAL/UTC button, its not triggering, but its update only when time changes. 您可以尝试增加间隔并尝试更改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))
  )

What you are looking for is combineLatest (not withLatestFrom ). 您正在寻找的是CombineLatest (不是withLatestFrom )。

withLatestFrom withLatestFrom

Combines the source with another observable (or more!) into an observable emitting arrays with latest values of each, only when the source emits . 仅在源发出时将源与另一个可观察到的(或更多!)组合成具有每个最新值的可观察发射阵列。

combineLatest 结合最新

Combines multiple observables into an observable that emits an array with the latest values of each source, every time one of these observables emits . 将多个可观察到发射与每一次这些可观测量的一个发射的每个源的最新值,阵列可观察到的。

This is the example for combineLatest: 这是CombineLatest的示例:

const firstTimer = timer(0, 1000); // emit 0, 1, 2... after every second, starting from now
const secondTimer = timer(500, 1000); // emit 0, 1, 2... after every second, starting 0,5s from now
const combinedTimers = combineLatest(firstTimer, secondTimer);
combinedTimers.subscribe(value => console.log(value));
// Logs
// [0, 0] after 0.5s
// [1, 0] after 1s
// [1, 1] after 1.5s
// [2, 1] after 2s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM