Created
January 8, 2021 15:28
-
-
Save mindscratch/22d507f8401dc9f78627db8c61b3f931 to your computer and use it in GitHub Desktop.
NgRX parameterized selector problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { State } from '../shared'; | |
constructor(store: Store<State>) { | |
// this call to errors because I haven't passed a "state" | |
store.select(selectNotificationsByGroupType(), { type: this.group.type }); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface State { | |
groups: NotificationGroup[]; | |
error: string | null; | |
} | |
export const selectAll = createSelector( | |
(state: State) => state.groups, | |
(groups: NotificationGroup[]) => groups | |
); | |
// parameterized selector to get notifications by group type | |
export const selectNotificationsByGroupType = () => | |
createSelector( | |
(state: State, props) => | |
state.groups.find((group) => group.type === props.type), | |
(group) => (group ? group.notifications : []) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment