【发布时间】:2017-08-18 21:38:08
【问题描述】:
我有一个关于 RxJS combineLatest 运算符的查询。我已经修改了
中给出的示例https://www.learnrxjs.io/operators/combination/combinelatest.html
如下:
//timerOne emits first value at 1s, then once every 4s
const timerOne = Rx.Observable.timer(1000, 4000);
//timerTwo emits first value at 2s, then once every 4s
const timerTwo = Rx.Observable.timer(2000, 4000)
//timerThree emits first value at 3s, then once every 4s
const timerThree = Rx.Observable.of(false);
//when one timer emits, emit the latest values from each timer as an array
const combined = Rx.Observable
.combineLatest(
timerOne,
timerTwo,
timerThree
);
const subscribe = combined.subscribe(latestValues => {
//grab latest emitted values for timers one, two, and three
const [timerValOne, timerValTwo, timerValThree] = latestValues;
if(latestValues[0] === 3) {
this.timerThree = Rx.Observable.of(true);
}
console.log(
`Timer One Latest: ${timerValOne},
Timer Two Latest: ${timerValTwo},
Timer Three Latest: ${timerValThree}`
);
});
我希望 timerThree 的值更改为 true 位,它总是继续打印 false,如输出 sn-p 所示:
"Timer One Latest: 3,
Timer Two Latest: 2,
Timer Three Latest: false"
"Timer One Latest: 3,
Timer Two Latest: 3,
Timer Three Latest: false"
"Timer One Latest: 4,
Timer Two Latest: 3,
Timer Three Latest: false"
知道为什么会这样吗?有没有什么办法解决这一问题?谢谢
【问题讨论】:
标签: javascript angular rx-java rxjs5