Suppose I have an event type, such as a click event. I need to initiate 3 separate ajax requests through this event, but I want to listen for the final result of all 3 requests.
What would be the most suitable design pattern for implementing this sequence?
The current code snippet that I am working with is outlined below:
$rootScope.$eventToObservable('selectUser')
.throttle(500)
.map(data => {
return angular.copy(data.additionalArguments[0].entity);
})
.select(d => {
return {
Member: MemberService.getMember(d.ID),
otherData: MemberService.dataOtherData(d.ID),
Notes: MemberService.getNotes(d.ID),
Log: MemberService.getLog(d.ID)
}
})
.switchLatest() // The code encounters an error here stating that "object is not a function". This could be due to the fact that the return object is not an observable. However, I am unsure about the correct design pattern to follow in this scenario.
.subscribe(model => {
// It is expected that the 'model' will contain an object with the result of the 3 responses mentioned above.
$scope.model = model;
});