我有getUserData$(userId)
,它根据下拉选择返回用户数据,如果userId不提供,则返回默认流,
pauser
反映了暂停/播放状态,
var clicks = Observable.fromEvent(document, 'click')
.map(function() {
var pauseStatus= state.get('dashboard').get('pauseStatus')
return pauseStatus;
});
var pauser = new Subject();
clicks.subscribe(pauser);
我想在不同的流之间切换并使它们也可暂停:
var sources = [];
var newSub =()=>{return new Subject();}
sources.push(newSub());
getUserData$().subscribe(sources[0]);
//if new user is selected from dropdown
if(user_id){
sources.push(newSub());
getUserData$(user_id).subscribe(sources[sources.length-1]);
}
var pausable = pauser.switchMap(paused => paused ? Observable.empty() : sources[sources.length-1]);
pausable.subscribe(function(result){...})
但是它会在两个流同时渲染时不断跳转,这是我做错了吗?