从商店中正确选择状态

我想在ngrx存储中订阅某个状态,并且仅在该特定状态发生更改时才接收排放。

myStr1 = b'1' myStr0 = b'0' serialC.write(myStr1) print(int(serialC.read().decode()))

export const getMatchesState = (state: State) => state.matches;

当我订阅这个赞

export const getSpainmatches = createSelector(getMatchesState,(allMatches) => {
  return Object.keys(allMatches.byId)
    .filter(key => {
      return allMatches.byId[key].tournamentId == '68';
    }).map(key => allMatches.byId[key]);
});

每次商店匹配更改时,我都会得到排放,不仅是西班牙匹配发生了变化。

更新

我也尝试过:

this.testSub = this.store.pipe(select(fromRoot.getSpainmatches))
      .subscribe(s => console.log('@@@@',s));
export const getSpainmatches = createSelector(getMatchesState,(allMatches,props) => {
  return Object.keys(allMatches.byId)
    .filter(key => {
      return allMatches.byId[key].tournamentId == props.tournamentId ;
    }).map(key => allMatches.byId[key]);
});

谢谢

sunlei890325sunlei 回答:从商店中正确选择状态

您可以尝试在某个地方使用distinctUntilChanged,也许在您的订阅中使用。

this.testSub = this.store.pipe(distinctUntilChanged(),select(fromRoot.getSpainMatches))
      .subscribe(s => console.log('@@@@',s));
本文链接:https://www.f2er.com/3143175.html

大家都在问