我想在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]);
});
谢谢
答案 0 :(得分:0)
您可以尝试在某个地方使用distinctUntilChanged,也许在您的订阅中使用。
this.testSub = this.store.pipe(distinctUntilChanged(), select(fromRoot.getSpainMatches))
.subscribe(s => console.log('@@@@', s));