rxjs operators for combine response

Published

I have below existing nested subscriptions (angular 6 project ) of streams but it depends upon the first observables response wherein it loads action from the store and then fires two subscriptions from store.

this.store.pipe(select(getOrganizationDetails),
         takeWhile(() => this.componentActive))
         .subscribe(resOrganization => {
            if (resOrganization) {
                 this.organization = resOrganization;
                this.store.dispatch(new mangeIconsActions.LoadIcons(this.organization.id));
                this.store.pipe(select(fromManageIcons.getContentIcons),takeWhile(()=>this.componentActive)).subscribe(contentIcons=>{
                    this.contentIcons=contentIcons;
                });
                 //loading module Icons
                this.store.pipe(select(fromManageIcons.getModuleIcons),takeWhile(()=>this.componentActive)).subscribe(moduleIcons=>{
                if(moduleIcons) {
               // Trending IconURl
                const trendingIconData=moduleIcons.find(moduleIcon=>moduleIcon.moduleName ==='Trending');
                if(Object.keys(trendingIconData).length > 0  && (trendingIconData.customModuleIconUrl !='' || trendingIconData.customModuleIconUrl !=null )) {
                    this.trendingIconUrl =trendingIconData.customModuleIconUrl;
                 }
                }
                });



             }

I did it as below wherein first I am using switchMap and tap to load action and then fire inner subscription using forkJoin but it is not working and not giving any response.

 this.store.pipe(select(getOrganizationDetails),takeWhile(()=>this.componentActive)).pipe(
            tap(res=>this.store.dispatch(new mangeIconsActions.LoadIcons(res.id))),
            switchMap(res=>
                forkJoin(
                this.store.pipe(select(fromManageIcons.getContentIcons),takeWhile(()=>this.componentActive)),
                this.store.pipe(select(fromManageIcons.getModuleIcons),takeWhile(()=>this.componentActive))
            )))
            .subscribe(([contentIcons,moduleIcons])=>{
                    alert(JSON.stringify(contentIcons));
                    alert(JSON.stringify(moduleIcons));
            })

Can anyone help me what is wrong here.

Source: Angular Questions

Published
Categorized as angular, rxjs6 Tagged ,

Answers

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq