I have this setup:
public listenCampaignSelected(){
var campaignSelected$ = this.store
.select(store => store.appDb.uiState.campaign.campaignSelected)
var campaigns$ = this.store
.select(store => store.msDatabase.sdk.table_campaigns);
return campaignSelected$.concatMap(
v => campaigns$,
(campaignId,campaigns) => {
return campaigns.find((i_campaign: CampaignsModelExt) => {
return i_campaign.getCampaignId() == campaignId;
});
})
}
and nothing emits except on the first subscribtion. now values ARE changing in $campaignSelected, I can see the store being updated.
this is how I subscribe:
this.yp.listenCampaignSelected().subscribe(
(campaign:CampaignsModelExt) => {
this.campaignModel = campaign;
this.renderFormInputs();
});
Now here is the interesting thing, if I change concatMap to switchMap all works.
so I am trying to understand why switchMap will work in this case and concatMap does not
So the answer is, concatMap will not work since the 2nd stream does not change change / fire. Thus you want to use switchMap which switches over the new stream regardless of any changes on that stream:
var campaignSelected$ = this.store.select(store => store.appDb.uiState.campaign.campaignSelected)
var campaigns$ = this.store.select(store => store.msDatabase.sdk.table_campaigns);
return campaignSelected$.switchMap(v => campaigns$, (campaignId,campaigns)=> {
return campaigns.find((i_campaign: CampaignsModelExt) => {
return i_campaign.getCampaignId() == campaignId;
});
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With