I'm using forkJoin
to turn several observables into one which I then map over to transform into some view model that I use for my view in my component.
My model is as follows:
export interface MyModel {
itemOne: Observable<ItemOne[]>;
itemTwo: Observable<ItemTwo[]>;
itemThree: Observable<ItemThree[]>;
}
My forkJoin
looks like:
this._subscriptions.push(this.myService.getData()
.flatMap(data => Observable.forkJoin(data
.map(data => {
let myModel: MyModel = {
itemOne: this.myService.getSomeData(),
itemTwo: this.myService.getSomeData(),
itemThree: this.myService.getSomeData()
};
return Observable.forkJoin(Observable.from([myModel]));
}))).subscribe(details => {
details.map(this.toMyModelViewModel.bind(this));
}));
Now, in my toMyModelViewModel
method, I'd like to pick each value from these Observables and was wondering how I could accomplish this?
toMyModelViewModel(value: MyModel): any {
return {
itemOne: value.itemOne,
itemTwo: value.itemTwo,
itemThree: value.itemThree
};
}
Do I have to subscribe to each value to get the current value or is there another, possible better/cleaner way of doing this? Ultimately, I'd like to have an array of MyModel objects that way I don't have to worry about using data | async
in my view.
Thanks