RXJS - Multiple observable calls on array of propertiesWhat is the difference between Promises and Observables?Angular/RxJs When should I unsubscribe from `Subscription`Can't bind to 'ngModel' since it isn't a known property of 'input'BehaviorSubject vs Observable?Angular2 making multiple requests using rxjs subscribeRXJS observable unsubscribe inner observablesProcess data depending on multiples observablesrxjs Operator that converts Observable<List<X>> to Observable<X>RxJS map & other operators with Observableupdating a list of objects within an observable using RxJS 6 and Angular 6
Unexpected email from Yorkshire Bank
How to creep the reader out with what seems like a normal person?
Why was Germany not as successful as other Europeans in establishing overseas colonies?
Visualizing a complicated Region
Is there a QGIS plugin that reclassify raster symbology based on current extent?
Is it the same airport YUL and YMQ in Canada?
How did Arya manage to disguise herself?
Does the time required to copy a spell into a spellbook have to be consecutive, or is that just the cumulative time required?
How long can a 35mm film be used/stored before it starts to lose its quality after expiry?
Selecting a secure PIN for building access
If I supply 24v to a 50v rated 22000uf electrolytic capacitor, does that mean it will store 44000uf at 24v?
Field Length Validation for Desktop Application which has maximum 1000 characters
What are the spoon bit of a spoon and fork bit of a fork called?
Copy line and insert it in a new position with sed or awk
A non-technological, repeating, visible object in the sky, holding its position in the sky for hours
How to back up a running Linode server?
Can I use 1000v rectifier diodes instead of 600v rectifier diodes?
Public Salesforce Site and Security Review
What happened to Ghost?
Floor tile layout process?
Problems with numbers (result of calculations) alignment using siunitx package inside tabular environment
What word means "to make something obsolete"?
What is the word which sounds like "shtrass"?
Is balancing necessary on a full-wheel change?
RXJS - Multiple observable calls on array of properties
What is the difference between Promises and Observables?Angular/RxJs When should I unsubscribe from `Subscription`Can't bind to 'ngModel' since it isn't a known property of 'input'BehaviorSubject vs Observable?Angular2 making multiple requests using rxjs subscribeRXJS observable unsubscribe inner observablesProcess data depending on multiples observablesrxjs Operator that converts Observable<List<X>> to Observable<X>RxJS map & other operators with Observableupdating a list of objects within an observable using RxJS 6 and Angular 6
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm kind off new to rxjs, and I've a fairly simple case that I can't work out in angular.
I've a http call to retrieve a group, this group contains a list of "buddy ids", a list of "genre ids" and a "region id".
To get the buddy objects trough the "buddy ids", I have to make a call to an API trough my service ( which return 1 buddy with given id ).
To get my genre objects, I can retrieve them form my store, same for region.
The problem is I can't have a solution worked out with pipes.
this.buddyService.getGroup(groupId).pipe(
mergeMap((group) => forkJoin(
mergeMap(() => forkJoin(group.buddyIds.map((id) => this.buddyService.getBuddy(id)))),
mergeMap(() => forkJoin(group.genreIds.map((id) => this.store.select(GenreState.genre(id))))),
switchMap(() => this.store.select(RegionState.region(group.regionId))))
), takeUntil(this.destroyed$)
).subscribe(([group, buddies, genres, region]) =>
);
So the first mergeMap will be to get all the results togehter in 1 subscribe, then I've 3 sub calls to get the buddies, genres and the region.
I'd like to have my initial response ( the group ) and the results of the 3 subcalls in 1 subscribe, obviously this solution doesn't work, and I can't seem to get something else to work.
Any help would be appreciated, thanks !
add a comment |
I'm kind off new to rxjs, and I've a fairly simple case that I can't work out in angular.
I've a http call to retrieve a group, this group contains a list of "buddy ids", a list of "genre ids" and a "region id".
To get the buddy objects trough the "buddy ids", I have to make a call to an API trough my service ( which return 1 buddy with given id ).
To get my genre objects, I can retrieve them form my store, same for region.
The problem is I can't have a solution worked out with pipes.
this.buddyService.getGroup(groupId).pipe(
mergeMap((group) => forkJoin(
mergeMap(() => forkJoin(group.buddyIds.map((id) => this.buddyService.getBuddy(id)))),
mergeMap(() => forkJoin(group.genreIds.map((id) => this.store.select(GenreState.genre(id))))),
switchMap(() => this.store.select(RegionState.region(group.regionId))))
), takeUntil(this.destroyed$)
).subscribe(([group, buddies, genres, region]) =>
);
So the first mergeMap will be to get all the results togehter in 1 subscribe, then I've 3 sub calls to get the buddies, genres and the region.
I'd like to have my initial response ( the group ) and the results of the 3 subcalls in 1 subscribe, obviously this solution doesn't work, and I can't seem to get something else to work.
Any help would be appreciated, thanks !
add a comment |
I'm kind off new to rxjs, and I've a fairly simple case that I can't work out in angular.
I've a http call to retrieve a group, this group contains a list of "buddy ids", a list of "genre ids" and a "region id".
To get the buddy objects trough the "buddy ids", I have to make a call to an API trough my service ( which return 1 buddy with given id ).
To get my genre objects, I can retrieve them form my store, same for region.
The problem is I can't have a solution worked out with pipes.
this.buddyService.getGroup(groupId).pipe(
mergeMap((group) => forkJoin(
mergeMap(() => forkJoin(group.buddyIds.map((id) => this.buddyService.getBuddy(id)))),
mergeMap(() => forkJoin(group.genreIds.map((id) => this.store.select(GenreState.genre(id))))),
switchMap(() => this.store.select(RegionState.region(group.regionId))))
), takeUntil(this.destroyed$)
).subscribe(([group, buddies, genres, region]) =>
);
So the first mergeMap will be to get all the results togehter in 1 subscribe, then I've 3 sub calls to get the buddies, genres and the region.
I'd like to have my initial response ( the group ) and the results of the 3 subcalls in 1 subscribe, obviously this solution doesn't work, and I can't seem to get something else to work.
Any help would be appreciated, thanks !
I'm kind off new to rxjs, and I've a fairly simple case that I can't work out in angular.
I've a http call to retrieve a group, this group contains a list of "buddy ids", a list of "genre ids" and a "region id".
To get the buddy objects trough the "buddy ids", I have to make a call to an API trough my service ( which return 1 buddy with given id ).
To get my genre objects, I can retrieve them form my store, same for region.
The problem is I can't have a solution worked out with pipes.
this.buddyService.getGroup(groupId).pipe(
mergeMap((group) => forkJoin(
mergeMap(() => forkJoin(group.buddyIds.map((id) => this.buddyService.getBuddy(id)))),
mergeMap(() => forkJoin(group.genreIds.map((id) => this.store.select(GenreState.genre(id))))),
switchMap(() => this.store.select(RegionState.region(group.regionId))))
), takeUntil(this.destroyed$)
).subscribe(([group, buddies, genres, region]) =>
);
So the first mergeMap will be to get all the results togehter in 1 subscribe, then I've 3 sub calls to get the buddies, genres and the region.
I'd like to have my initial response ( the group ) and the results of the 3 subcalls in 1 subscribe, obviously this solution doesn't work, and I can't seem to get something else to work.
Any help would be appreciated, thanks !
asked Mar 22 at 20:08
TanguyBTanguyB
9721133
9721133
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
This version is a little more verbose, but might be easier to reason about as it is divided into several chunks. Haven't tested it though.
import combineLatest from 'rxjs';
...
const group$ = this.buddyService.getGroup(groupId);
const buddies$ = group$.pipe(mergeMap(group => combineLatest(group.buddyIds.map((id) => this.buddyService.getBuddy(id))));
const genres$ = group$.pipe(mergeMap(group => combineLatest(group.genreIds.map((id) => this.store.select(GenreState.genre(id))));
const region$ = group$.pipe(switchMap(group => this.store.select(RegionState.region(group.regionId)))));
combineLatest([group$, buddies$, genres$, region$])
.pipe(takeUntil(this.destroyed$))
.subscribe(([group, buddies, genres, region]) => );
I tried your solution, it doesn't seem to hit the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:19
So forkJoin assumes that all the Observables completes, but that is probably not the case with the store.select. I have changed the last forkJoin to a combineLatest, that might solve the issue.
– SnorreDan
Mar 22 at 23:37
Alternatively we could make the store.select complete by changing it to "this.store.select(RegionState.region(group.regionId)).pipe(take(1))".
– SnorreDan
Mar 22 at 23:46
I changed all the forkJoins in the example to combineLatest now, then it should work. But if what you want is to get just one value, then you should change back to forkJoin, and add the ".pipe(take(1))" after all the observables that does not complete.
– SnorreDan
Mar 22 at 23:51
yeah the problem was indeed the store.select ( if i do a selectsnapshot on the store in subscribe it works ). I'll try with your latest solution
– TanguyB
Mar 22 at 23:55
add a comment |
Seems you have too many inner mergeMaps. Try this
this.buddyService.getGroup(groupId).pipe(
mergeMap((group) => forkJoin(
of(group),
forkJoin(...group.buddyIds.map((id) => this.buddyService.getBuddy(id))),
forkJoin(...group.genreIds.map((id) => this.store.select(GenreState.genre(id)))),
this.store.select(RegionState.region(group.regionId)))
),
takeUntil(this.destroyed$)
)
.subscribe(([group, buddies, genres, region]) => );
The main issue was that you've combined "constructing" methods that create Observables (like forkJoin) with operators that operate on existing Observables (like switchMap or mergeMap).
Test the difference yourself: switchMap vs forkJoin
I've written this w/o deep testing, so it might not work immediately :)
1
I'll try it out later in the evening and respond if it works, thanks though, I'm very new to rxjs so it's a lot :)
– TanguyB
Mar 22 at 21:00
do you have any resources outside of the official docs for rxjs, I don't find them that clear
– TanguyB
Mar 22 at 21:07
@TanguyB, well, on practical side -- I would highly recommend the rxjs playground I've created. On theoretical side -- I feel your pain, current documentation mostly lacks simplicity and transparency. Try learnrxjs.io -- they have good examples and theres this old book on RxJS 4 that you might get some concepts from. + there are couple of egghead courses on RxJS, though they are behind a paywall.
– Kos
Mar 22 at 21:24
@TanguyB, I've just googled for some rxjs resources -- and theres a tonn of tutorials and articles on this theme, actually. Though since I see most of them for the first time -- I cant honestly recommend them. Yet, here are two videos that might help you with a start: RxJS Quick Start with Practical Examples and a series of video tuts by RxJS core contributors Ben Lesh and Tracy Lee. Basically just google around, you'll find what fits you best! ;)
– Kos
Mar 22 at 22:07
@Hi, I tried your solution, it doesn't seel to get in the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:18
|
show 1 more comment
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307110%2frxjs-multiple-observable-calls-on-array-of-properties%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This version is a little more verbose, but might be easier to reason about as it is divided into several chunks. Haven't tested it though.
import combineLatest from 'rxjs';
...
const group$ = this.buddyService.getGroup(groupId);
const buddies$ = group$.pipe(mergeMap(group => combineLatest(group.buddyIds.map((id) => this.buddyService.getBuddy(id))));
const genres$ = group$.pipe(mergeMap(group => combineLatest(group.genreIds.map((id) => this.store.select(GenreState.genre(id))));
const region$ = group$.pipe(switchMap(group => this.store.select(RegionState.region(group.regionId)))));
combineLatest([group$, buddies$, genres$, region$])
.pipe(takeUntil(this.destroyed$))
.subscribe(([group, buddies, genres, region]) => );
I tried your solution, it doesn't seem to hit the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:19
So forkJoin assumes that all the Observables completes, but that is probably not the case with the store.select. I have changed the last forkJoin to a combineLatest, that might solve the issue.
– SnorreDan
Mar 22 at 23:37
Alternatively we could make the store.select complete by changing it to "this.store.select(RegionState.region(group.regionId)).pipe(take(1))".
– SnorreDan
Mar 22 at 23:46
I changed all the forkJoins in the example to combineLatest now, then it should work. But if what you want is to get just one value, then you should change back to forkJoin, and add the ".pipe(take(1))" after all the observables that does not complete.
– SnorreDan
Mar 22 at 23:51
yeah the problem was indeed the store.select ( if i do a selectsnapshot on the store in subscribe it works ). I'll try with your latest solution
– TanguyB
Mar 22 at 23:55
add a comment |
This version is a little more verbose, but might be easier to reason about as it is divided into several chunks. Haven't tested it though.
import combineLatest from 'rxjs';
...
const group$ = this.buddyService.getGroup(groupId);
const buddies$ = group$.pipe(mergeMap(group => combineLatest(group.buddyIds.map((id) => this.buddyService.getBuddy(id))));
const genres$ = group$.pipe(mergeMap(group => combineLatest(group.genreIds.map((id) => this.store.select(GenreState.genre(id))));
const region$ = group$.pipe(switchMap(group => this.store.select(RegionState.region(group.regionId)))));
combineLatest([group$, buddies$, genres$, region$])
.pipe(takeUntil(this.destroyed$))
.subscribe(([group, buddies, genres, region]) => );
I tried your solution, it doesn't seem to hit the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:19
So forkJoin assumes that all the Observables completes, but that is probably not the case with the store.select. I have changed the last forkJoin to a combineLatest, that might solve the issue.
– SnorreDan
Mar 22 at 23:37
Alternatively we could make the store.select complete by changing it to "this.store.select(RegionState.region(group.regionId)).pipe(take(1))".
– SnorreDan
Mar 22 at 23:46
I changed all the forkJoins in the example to combineLatest now, then it should work. But if what you want is to get just one value, then you should change back to forkJoin, and add the ".pipe(take(1))" after all the observables that does not complete.
– SnorreDan
Mar 22 at 23:51
yeah the problem was indeed the store.select ( if i do a selectsnapshot on the store in subscribe it works ). I'll try with your latest solution
– TanguyB
Mar 22 at 23:55
add a comment |
This version is a little more verbose, but might be easier to reason about as it is divided into several chunks. Haven't tested it though.
import combineLatest from 'rxjs';
...
const group$ = this.buddyService.getGroup(groupId);
const buddies$ = group$.pipe(mergeMap(group => combineLatest(group.buddyIds.map((id) => this.buddyService.getBuddy(id))));
const genres$ = group$.pipe(mergeMap(group => combineLatest(group.genreIds.map((id) => this.store.select(GenreState.genre(id))));
const region$ = group$.pipe(switchMap(group => this.store.select(RegionState.region(group.regionId)))));
combineLatest([group$, buddies$, genres$, region$])
.pipe(takeUntil(this.destroyed$))
.subscribe(([group, buddies, genres, region]) => );
This version is a little more verbose, but might be easier to reason about as it is divided into several chunks. Haven't tested it though.
import combineLatest from 'rxjs';
...
const group$ = this.buddyService.getGroup(groupId);
const buddies$ = group$.pipe(mergeMap(group => combineLatest(group.buddyIds.map((id) => this.buddyService.getBuddy(id))));
const genres$ = group$.pipe(mergeMap(group => combineLatest(group.genreIds.map((id) => this.store.select(GenreState.genre(id))));
const region$ = group$.pipe(switchMap(group => this.store.select(RegionState.region(group.regionId)))));
combineLatest([group$, buddies$, genres$, region$])
.pipe(takeUntil(this.destroyed$))
.subscribe(([group, buddies, genres, region]) => );
edited Mar 22 at 23:48
answered Mar 22 at 21:15
SnorreDanSnorreDan
722412
722412
I tried your solution, it doesn't seem to hit the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:19
So forkJoin assumes that all the Observables completes, but that is probably not the case with the store.select. I have changed the last forkJoin to a combineLatest, that might solve the issue.
– SnorreDan
Mar 22 at 23:37
Alternatively we could make the store.select complete by changing it to "this.store.select(RegionState.region(group.regionId)).pipe(take(1))".
– SnorreDan
Mar 22 at 23:46
I changed all the forkJoins in the example to combineLatest now, then it should work. But if what you want is to get just one value, then you should change back to forkJoin, and add the ".pipe(take(1))" after all the observables that does not complete.
– SnorreDan
Mar 22 at 23:51
yeah the problem was indeed the store.select ( if i do a selectsnapshot on the store in subscribe it works ). I'll try with your latest solution
– TanguyB
Mar 22 at 23:55
add a comment |
I tried your solution, it doesn't seem to hit the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:19
So forkJoin assumes that all the Observables completes, but that is probably not the case with the store.select. I have changed the last forkJoin to a combineLatest, that might solve the issue.
– SnorreDan
Mar 22 at 23:37
Alternatively we could make the store.select complete by changing it to "this.store.select(RegionState.region(group.regionId)).pipe(take(1))".
– SnorreDan
Mar 22 at 23:46
I changed all the forkJoins in the example to combineLatest now, then it should work. But if what you want is to get just one value, then you should change back to forkJoin, and add the ".pipe(take(1))" after all the observables that does not complete.
– SnorreDan
Mar 22 at 23:51
yeah the problem was indeed the store.select ( if i do a selectsnapshot on the store in subscribe it works ). I'll try with your latest solution
– TanguyB
Mar 22 at 23:55
I tried your solution, it doesn't seem to hit the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:19
I tried your solution, it doesn't seem to hit the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:19
So forkJoin assumes that all the Observables completes, but that is probably not the case with the store.select. I have changed the last forkJoin to a combineLatest, that might solve the issue.
– SnorreDan
Mar 22 at 23:37
So forkJoin assumes that all the Observables completes, but that is probably not the case with the store.select. I have changed the last forkJoin to a combineLatest, that might solve the issue.
– SnorreDan
Mar 22 at 23:37
Alternatively we could make the store.select complete by changing it to "this.store.select(RegionState.region(group.regionId)).pipe(take(1))".
– SnorreDan
Mar 22 at 23:46
Alternatively we could make the store.select complete by changing it to "this.store.select(RegionState.region(group.regionId)).pipe(take(1))".
– SnorreDan
Mar 22 at 23:46
I changed all the forkJoins in the example to combineLatest now, then it should work. But if what you want is to get just one value, then you should change back to forkJoin, and add the ".pipe(take(1))" after all the observables that does not complete.
– SnorreDan
Mar 22 at 23:51
I changed all the forkJoins in the example to combineLatest now, then it should work. But if what you want is to get just one value, then you should change back to forkJoin, and add the ".pipe(take(1))" after all the observables that does not complete.
– SnorreDan
Mar 22 at 23:51
yeah the problem was indeed the store.select ( if i do a selectsnapshot on the store in subscribe it works ). I'll try with your latest solution
– TanguyB
Mar 22 at 23:55
yeah the problem was indeed the store.select ( if i do a selectsnapshot on the store in subscribe it works ). I'll try with your latest solution
– TanguyB
Mar 22 at 23:55
add a comment |
Seems you have too many inner mergeMaps. Try this
this.buddyService.getGroup(groupId).pipe(
mergeMap((group) => forkJoin(
of(group),
forkJoin(...group.buddyIds.map((id) => this.buddyService.getBuddy(id))),
forkJoin(...group.genreIds.map((id) => this.store.select(GenreState.genre(id)))),
this.store.select(RegionState.region(group.regionId)))
),
takeUntil(this.destroyed$)
)
.subscribe(([group, buddies, genres, region]) => );
The main issue was that you've combined "constructing" methods that create Observables (like forkJoin) with operators that operate on existing Observables (like switchMap or mergeMap).
Test the difference yourself: switchMap vs forkJoin
I've written this w/o deep testing, so it might not work immediately :)
1
I'll try it out later in the evening and respond if it works, thanks though, I'm very new to rxjs so it's a lot :)
– TanguyB
Mar 22 at 21:00
do you have any resources outside of the official docs for rxjs, I don't find them that clear
– TanguyB
Mar 22 at 21:07
@TanguyB, well, on practical side -- I would highly recommend the rxjs playground I've created. On theoretical side -- I feel your pain, current documentation mostly lacks simplicity and transparency. Try learnrxjs.io -- they have good examples and theres this old book on RxJS 4 that you might get some concepts from. + there are couple of egghead courses on RxJS, though they are behind a paywall.
– Kos
Mar 22 at 21:24
@TanguyB, I've just googled for some rxjs resources -- and theres a tonn of tutorials and articles on this theme, actually. Though since I see most of them for the first time -- I cant honestly recommend them. Yet, here are two videos that might help you with a start: RxJS Quick Start with Practical Examples and a series of video tuts by RxJS core contributors Ben Lesh and Tracy Lee. Basically just google around, you'll find what fits you best! ;)
– Kos
Mar 22 at 22:07
@Hi, I tried your solution, it doesn't seel to get in the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:18
|
show 1 more comment
Seems you have too many inner mergeMaps. Try this
this.buddyService.getGroup(groupId).pipe(
mergeMap((group) => forkJoin(
of(group),
forkJoin(...group.buddyIds.map((id) => this.buddyService.getBuddy(id))),
forkJoin(...group.genreIds.map((id) => this.store.select(GenreState.genre(id)))),
this.store.select(RegionState.region(group.regionId)))
),
takeUntil(this.destroyed$)
)
.subscribe(([group, buddies, genres, region]) => );
The main issue was that you've combined "constructing" methods that create Observables (like forkJoin) with operators that operate on existing Observables (like switchMap or mergeMap).
Test the difference yourself: switchMap vs forkJoin
I've written this w/o deep testing, so it might not work immediately :)
1
I'll try it out later in the evening and respond if it works, thanks though, I'm very new to rxjs so it's a lot :)
– TanguyB
Mar 22 at 21:00
do you have any resources outside of the official docs for rxjs, I don't find them that clear
– TanguyB
Mar 22 at 21:07
@TanguyB, well, on practical side -- I would highly recommend the rxjs playground I've created. On theoretical side -- I feel your pain, current documentation mostly lacks simplicity and transparency. Try learnrxjs.io -- they have good examples and theres this old book on RxJS 4 that you might get some concepts from. + there are couple of egghead courses on RxJS, though they are behind a paywall.
– Kos
Mar 22 at 21:24
@TanguyB, I've just googled for some rxjs resources -- and theres a tonn of tutorials and articles on this theme, actually. Though since I see most of them for the first time -- I cant honestly recommend them. Yet, here are two videos that might help you with a start: RxJS Quick Start with Practical Examples and a series of video tuts by RxJS core contributors Ben Lesh and Tracy Lee. Basically just google around, you'll find what fits you best! ;)
– Kos
Mar 22 at 22:07
@Hi, I tried your solution, it doesn't seel to get in the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:18
|
show 1 more comment
Seems you have too many inner mergeMaps. Try this
this.buddyService.getGroup(groupId).pipe(
mergeMap((group) => forkJoin(
of(group),
forkJoin(...group.buddyIds.map((id) => this.buddyService.getBuddy(id))),
forkJoin(...group.genreIds.map((id) => this.store.select(GenreState.genre(id)))),
this.store.select(RegionState.region(group.regionId)))
),
takeUntil(this.destroyed$)
)
.subscribe(([group, buddies, genres, region]) => );
The main issue was that you've combined "constructing" methods that create Observables (like forkJoin) with operators that operate on existing Observables (like switchMap or mergeMap).
Test the difference yourself: switchMap vs forkJoin
I've written this w/o deep testing, so it might not work immediately :)
Seems you have too many inner mergeMaps. Try this
this.buddyService.getGroup(groupId).pipe(
mergeMap((group) => forkJoin(
of(group),
forkJoin(...group.buddyIds.map((id) => this.buddyService.getBuddy(id))),
forkJoin(...group.genreIds.map((id) => this.store.select(GenreState.genre(id)))),
this.store.select(RegionState.region(group.regionId)))
),
takeUntil(this.destroyed$)
)
.subscribe(([group, buddies, genres, region]) => );
The main issue was that you've combined "constructing" methods that create Observables (like forkJoin) with operators that operate on existing Observables (like switchMap or mergeMap).
Test the difference yourself: switchMap vs forkJoin
I've written this w/o deep testing, so it might not work immediately :)
edited Mar 22 at 20:56
answered Mar 22 at 20:50
KosKos
1,160514
1,160514
1
I'll try it out later in the evening and respond if it works, thanks though, I'm very new to rxjs so it's a lot :)
– TanguyB
Mar 22 at 21:00
do you have any resources outside of the official docs for rxjs, I don't find them that clear
– TanguyB
Mar 22 at 21:07
@TanguyB, well, on practical side -- I would highly recommend the rxjs playground I've created. On theoretical side -- I feel your pain, current documentation mostly lacks simplicity and transparency. Try learnrxjs.io -- they have good examples and theres this old book on RxJS 4 that you might get some concepts from. + there are couple of egghead courses on RxJS, though they are behind a paywall.
– Kos
Mar 22 at 21:24
@TanguyB, I've just googled for some rxjs resources -- and theres a tonn of tutorials and articles on this theme, actually. Though since I see most of them for the first time -- I cant honestly recommend them. Yet, here are two videos that might help you with a start: RxJS Quick Start with Practical Examples and a series of video tuts by RxJS core contributors Ben Lesh and Tracy Lee. Basically just google around, you'll find what fits you best! ;)
– Kos
Mar 22 at 22:07
@Hi, I tried your solution, it doesn't seel to get in the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:18
|
show 1 more comment
1
I'll try it out later in the evening and respond if it works, thanks though, I'm very new to rxjs so it's a lot :)
– TanguyB
Mar 22 at 21:00
do you have any resources outside of the official docs for rxjs, I don't find them that clear
– TanguyB
Mar 22 at 21:07
@TanguyB, well, on practical side -- I would highly recommend the rxjs playground I've created. On theoretical side -- I feel your pain, current documentation mostly lacks simplicity and transparency. Try learnrxjs.io -- they have good examples and theres this old book on RxJS 4 that you might get some concepts from. + there are couple of egghead courses on RxJS, though they are behind a paywall.
– Kos
Mar 22 at 21:24
@TanguyB, I've just googled for some rxjs resources -- and theres a tonn of tutorials and articles on this theme, actually. Though since I see most of them for the first time -- I cant honestly recommend them. Yet, here are two videos that might help you with a start: RxJS Quick Start with Practical Examples and a series of video tuts by RxJS core contributors Ben Lesh and Tracy Lee. Basically just google around, you'll find what fits you best! ;)
– Kos
Mar 22 at 22:07
@Hi, I tried your solution, it doesn't seel to get in the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:18
1
1
I'll try it out later in the evening and respond if it works, thanks though, I'm very new to rxjs so it's a lot :)
– TanguyB
Mar 22 at 21:00
I'll try it out later in the evening and respond if it works, thanks though, I'm very new to rxjs so it's a lot :)
– TanguyB
Mar 22 at 21:00
do you have any resources outside of the official docs for rxjs, I don't find them that clear
– TanguyB
Mar 22 at 21:07
do you have any resources outside of the official docs for rxjs, I don't find them that clear
– TanguyB
Mar 22 at 21:07
@TanguyB, well, on practical side -- I would highly recommend the rxjs playground I've created. On theoretical side -- I feel your pain, current documentation mostly lacks simplicity and transparency. Try learnrxjs.io -- they have good examples and theres this old book on RxJS 4 that you might get some concepts from. + there are couple of egghead courses on RxJS, though they are behind a paywall.
– Kos
Mar 22 at 21:24
@TanguyB, well, on practical side -- I would highly recommend the rxjs playground I've created. On theoretical side -- I feel your pain, current documentation mostly lacks simplicity and transparency. Try learnrxjs.io -- they have good examples and theres this old book on RxJS 4 that you might get some concepts from. + there are couple of egghead courses on RxJS, though they are behind a paywall.
– Kos
Mar 22 at 21:24
@TanguyB, I've just googled for some rxjs resources -- and theres a tonn of tutorials and articles on this theme, actually. Though since I see most of them for the first time -- I cant honestly recommend them. Yet, here are two videos that might help you with a start: RxJS Quick Start with Practical Examples and a series of video tuts by RxJS core contributors Ben Lesh and Tracy Lee. Basically just google around, you'll find what fits you best! ;)
– Kos
Mar 22 at 22:07
@TanguyB, I've just googled for some rxjs resources -- and theres a tonn of tutorials and articles on this theme, actually. Though since I see most of them for the first time -- I cant honestly recommend them. Yet, here are two videos that might help you with a start: RxJS Quick Start with Practical Examples and a series of video tuts by RxJS core contributors Ben Lesh and Tracy Lee. Basically just google around, you'll find what fits you best! ;)
– Kos
Mar 22 at 22:07
@Hi, I tried your solution, it doesn't seel to get in the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:18
@Hi, I tried your solution, it doesn't seel to get in the subscribe part, any clues ?
– TanguyB
Mar 22 at 23:18
|
show 1 more comment
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55307110%2frxjs-multiple-observable-calls-on-array-of-properties%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown