Answer the question
In order to leave comments, you need to log in
RxJs. why two subscriptions to one observable don't work?
there is an observable created from a Subject:
private searchData$: Observable<ISearchData>;
constructor (private conService: ConnectionService) {
this.searchData$ = <Observable<ISearchData>>conService.messages.pipe(
filter((message) => {
return message.key === QUERYBASE.search.key;
}),
map ((message)=>{
return message.data as ISearchData;
})
);
}
public startSearch(){
let queryData: ISearchQueryData = ...
this.searchDataSub = this.searchData$.subscribe(
(data)=>{
console.log("Get search data: ",data);
if (data.hash !== this.lastHash) {
this.items = data.search;
this.lastHash = data.hash;
}
this.searchDone = data.done;
}
);
const newSub = this.searchData$.pipe(
delay(2000)
).subscribe(
(data)=> {
console.log("sub2", data);
//!data.done && this.conService.search(queryData);
}
);
this.conService.search(queryData);
}
this.searchDataSub = this.searchData$.subscribe(
(data)=>{
console.log("Get search data: ",data);
/*...*/
}
);
const newSub = this.searchData$.subscribe(
(data)=> {
console.log("sub2", data);
//...
}
);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question