我有来自interval的Rx Observable和来自react prop的另一个观察点,我确实与withLatestFrom合并了这两个观察点,以侦听更新并使用recompose渲染流组件,它工作得很好,但问题是当我将prop改为local到utc时,它没有更新。
您可以尝试增加间隔,并尝试更改LOCAL/UTC按钮,它不会触发,但只有在时间改变时才会更新。
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))
)发布于 2018-10-01 04:44:44
你要找的是 (不是)。
withLatestFrom
将源与另一个可观察对象(或更多!)转换为可观察的发射数组,每个数组的最新值为each,仅当源发射时才为。
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 2shttps://stackoverflow.com/questions/52576529
复制相似问题