Trying to construct a schedule using RxJS v5, where certain events can trigger the schedule to reload. Currently using 3 sources - schedule$, event$, and userNotification$ (example below).
I've tried a number of different strategies and I'm consistently getting weirdness like recursive reloads when the reloadSchedule event time hits. Is there a way for downstream data (event$) to cleanly trigger upstream (schedule$) reloads, without any actions/notifications lingering from previous schedule items?
schedule$ = new Rx.BehaviorSubject(
{schedule:[
{start:'1pm', end:'2pm', action:'sayhi'},
{start:'2pm', end:'3pm', action:'sayhi'},
{start:'3pm', end:'3pm', action:'reloadSchedule'},
{start:'3:01pm', end:'4pm', action:'sayhi'},
]}
);
function loadSchedule(){
somethingAsync.then((moreData)=>schedule$.next(moreData));
}
event$ = schedule$.flatMap((data)=>{
return Rx.Observable
.from(data.schedule)
.flatMap((event)=>{
return Rx.Observable.timer(event.start)
.flatMap(()=>{
// do actions here once previous actions/notifications finish
if(event.action === 'reloadSchedule'){
loadSchedule()
}
return Rx.Observable.of(someUserMessage);
})
})
})
userNotification$ = Rx.Observable.timer(1000).withLatestFrom(event$)
.flatMap((someUserMessage)={
// fade message after 5 seconds
});
userNotification.subscribe(()=>{});