Ngrx: combine to selectors -
i've built istore:
export interface istore { user: iuser; sources: isourceredux; } where iuser is:
export interface iuser { id: string; cname: string; sname: string; ... } and isourceredux is:
export interface isourceredux { entities: { [key: string]: isource }; ids: array<string>; selectedids: array<string>; editingsource: isource; defaultid: string; } so, i've created these selectors:
export const getsourcesstate = (state: istore) => state.sources; export const getselectedids = (sourcerdx: isourceredux) => sourcerdx.selectedids; export const getselectedsourceids = createselector(getsourcesstate, fromsources.getselectedids); so, now, in order check if user logged did that:
this.store$ .select(fromroot.getuserstate) .filter(user => user.id != null && user.logged) .do(user => this.store$.dispatch(...)) ... now i'm strugling getting user information , selectedsourceids @ same time in order check if:
- a user logged (
this.store$.select(fromroot.getuserstate) - then selectedsourceids (
this.store.select(fromroot.getselectedsourceids)) - dispatch action
how this?
this solution:
this.store$.combinelatest( this.store$.select(fromroot.getuserentity), this.store$.select(fromroot.getselectedsourceids), (store, user, selectedsourceids) => ({user: user, selectedsourceids: selectedsourceids}) ) .filter((proj) => proj.user.id != null && proj.user.logged) .do((proj) => this.store$.dispatch({type: 'delete_cards', payload: {username: proj.user.username, tokens: proj.selectedsourceids}})) .take(1) .subscribe(); i hope it's useful.
Comments
Post a Comment