1
我已經建立了這個IStore
:NGRX:結合到選擇
export interface IStore {
user: IUser;
sources: ISourceRedux;
}
其中IUser
是:
export interface IUser {
id: string;
cname: string;
sname: string;
...
}
和ISourceRedux
是:
export interface ISourceRedux {
entities: { [key: string]: ISource };
ids: Array<string>;
selectedIds: Array<string>;
editingSource: ISource;
defaultId: string;
}
所以,我創建這些選擇器:
export const getSourcesState = (state: IStore) => state.sources;
export const getSelectedIds = (sourceRdx: ISourceRedux) => sourceRdx.selectedIds;
export const getSelectedSourceIds = createSelector(getSourcesState, fromSources.getSelectedIds);
所以,到現在爲止,以檢查是否有用戶登錄我這樣做:
this.store$
.select(fromRoot.getUserState)
.filter(user => user.id != null && user.logged)
.do(user => this.store$.dispatch(...))
...
現在我strugling用於獲取用戶信息和selectedSourceIds在同一時間,以便檢查如果:
- 用戶登錄(
this.store$.select(fromRoot.getUserState)
- 然後讓所有selectedSourceIds(
this.store.select(fromRoot.getSelectedSourceIds)
) - 調度一個動作
我怎麼能得到這個?
看看'withLatestFrom' RxJs運營商 – Maxime