【发布时间】:2019-11-07 16:21:25
【问题描述】:
我想订阅 ngrx 存储中的一个状态,并仅在该特定状态发生更改时接收排放。
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]);
});
当我订阅这个likeso时
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]);
});
this.testSub = this.store.pipe(select(fromRoot.getSpainMatches, {tournamentId: 68}))
.subscribe(s => console.log('@@@@', s));
谢谢
【问题讨论】: