在 RxJS 中,我希望订阅在流中保持不变,即使流发生了变化。下面我使用间隔流来测试行为
//Works because foo$ is unchanged
let foo$ = Rx.Observable.interval(1000);
foo$.subscribe(x => console.log(`foo$: ${x}`));
//Doesn't work because bar$ is changed
let bar$ = Rx.Observable.never();
bar$.subscribe(x => console.log(`bar$: ${x}`))
bar$ = Rx.Observable.interval(1000);
如何在更改bar$
流时保留订阅?更改 bar$ 后,我是否必须处理订阅并设置另一个订阅?