简体   繁体   English

concatMap没有得到后续存储发出

[英]concatMap not getting subsequent store emits

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. 现在$ campaignSelected中的值正在更改,我可以看到商店正在更新。

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. 现在,如果我将concatMap更改为switchMap所有的工作就switchMap了。

so I am trying to understand why switchMap will work in this case and concatMap does not 所以我试图理解为什么在这种情况下switchMap可以工作,而concatMap不能工作

So the answer is, concatMap will not work since the 2nd stream does not change change / fire. 所以答案是,concatMap将不起作用,因为第二个流不会更改change / fire。 Thus you want to use switchMap which switches over the new stream regardless of any changes on that stream: 因此,您想使用switchMap来切换新流,而不管对该流进行任何更改:

  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;
            });
        })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM