I need to create an Observable that will collect other observables coming from some http requests. The new observable must be a collection of same object type but every item must be unique. Can you help me writing the correct method to achieve this goal?
// The result observable that I need
topicCollection$ = BehaviorSubject<Topic[]> = new BehaviorSubject<Topic[]>(null);
// Boolean observable of authentication
isAuthenticated: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);
// Return default topic
get defaultTopics$(): Observable<Topic[]>{
return this.defaultTopic.asObservable();
}
// Return topics selected by Admin
get TopTopics$(): Observable<Topic[]>{
return this.topTopic.asObservable();
}
//Return topics selected by User
get userTopics$: Observable<Topic[]>{
return this.userTopic.asObservable();
}
//Return user settings
get userSettings$(): Observable<any[]>{
return this.userSettings.asObservable();
}
So the constraint are:
- If user is not logged collection must be in this order: defaultTopic, topTopic
- If user is logged collection must be in this order:defaultTopic, topTopic, userTopic
- If user is logged I will read the UserSettings$ that filter the defaultTopics if they will be hidden or shown
- Topic must be unique (duplicate topics would be only in default and user topic observable)
I try with combineLatest and forkJoin but I don't know how to differenziate the operators with the authentication observer.