Subscribing in subscription loses inner subscription
jerradpatch opened this issue · comments
I am not 100% sure where to go with this one (but pretty sure its meteor-rxjs), or even if I am doing something wrong.
I have an outer subscription that is waiting on the user to login, then triggers an inner subscription that fetches data for the logged in user.
The issue is that the find for the inner subscription does not return the data. I know the objects are in the local mongo. I know the find function is called. It just doesnt return the data. However, if I pull the find out of the login subscription. It returns the data just fine. Here is some code
Angular4 + typescript
//user class
private userState: BehaviorSubject<string> = new BehaviorSubject(null);
whenLoggedIn() : Observable<string> {
return this.userState;
}
//ui controller
ngOnInit() {
let thiss = this;
this.test = this.users.whenLoggedIn()
.subscribe(user=>{
if(user == "loggedIn"){
thiss.findData();
} else {
thiss.ngOnDestroy();
}
this.loggedIn = user;
});
}
ngOnDestroy() {
if(this.subThMod) {
this.subThMod.unsubscribe();
}
}
findData() {
this.subThMod = this.thWaMe_OuSe.findAll()
.subscribe(val=>{
debugger;
});
}
public findAll(): Observable<ModelThWaMe_OuSe[]> {
//Model = substantiated mongo collection observable
var ret = this.Model.find({})
.auditTime(50)
.do(()=>{
CommonLogic.debug(this, "ThWaMe_OuSe:findAll_idList");
})
.map(raws => {
return raws.map(raw=> {
return this.newModel(raw);
});
});
return ret;
}
the flow is this start->outerSub["loggedOut"]->ngOnDestroy()->outerSub['loggedIn']->findData()
then the debugger never hits.
However, 'findData()' constructor the debugger hits when the user is logged in (with user data).
I think its an meteor-rxjs issue due to this function works as expected when replaced with pure RXJS
function findData(){
Rx.Observable.interval(1000).mapTo("inner")
.subscribe((valI)=>{
console.log(valI);
});
}
Here will constantly output "inner" to the console as expected.
here is a jsbin for my situation and also what I would expect using pure RSJS.
http://jsbin.com/giliqip/edit?js,console
Thanks for your help.
I believe this was an issue with Hot and cold observables, and the data was coming back before I had subscribed.