-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(example): use featureKey for layout selector #2323
Conversation
Preview docs changes for 4b48e51 at https://previews.ngrx.io/pr2323-4b48e51/ |
691189f
to
55ab47c
Compare
a6a237e
to
4b48e51
Compare
|
@@ -69,7 +69,7 @@ export const metaReducers: MetaReducer<State>[] = !environment.production | |||
* Layout Reducers | |||
*/ | |||
export const selectLayoutState = createFeatureSelector<State, fromLayout.State>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just one generic is fine createFeatureSelector<fromLayout.State>(...)
Typically there is no global State
and many features are lazy-loaded, so there cannot be a single interface that connects them all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is to be added I guess it would imply changes to all other places where FeatureSelectors are being created e.g. https://github.com/ngrx/platform/blob/4b48e51f95/projects/example-app/src/app/auth/reducers/index.ts#L29 ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, yes. Maybe in the follow-up PRs.
Also, after PR #2325 lands there would be some more changes
@timdeschryver @brandonroberts hope you don't mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 2 generics are there to provide type safety, but you have to extend the Feature state with the Root State:
export interface State extends fromRoot.State {
[booksFeatureKey]: BooksState;
}
But this was before the usage of feature keys.
I think we could indeed refactor this, but I don't got a strong opinion on this.
Sometimes it will still be needed to extend from the root, this is when you're combining selectors from the feature with the root.
We can take this one in a later PR and merge this PR if everything is OK with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometimes it will still be needed to extend from the root, this is when you're combining selectors from the feature with the root.
There are workarounds for this :P
@alex-okrushko see 691189f for the original commit. The changes that were made were (but are now reverted): export const selectAuthState = createFeatureSelector<State, AuthState>(
authFeatureKey
);
export const selectAuthStatusState = createSelector(
selectAuthState,
- (state: AuthState) => state.status
+ (state: AuthState) => state[fromAuth.statusFeatureKey]
); But I'm not a big fan of using the feature keys for |
100% agree. Feature keys only for |
I agree also. Let the types flow from the top |
We will tackle this in follow-up PRs after #2325
Thanks @erhise |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Consistently use feature keys exported from reducer file, e.g. where selectors for underlying state are being created.
What is the current behavior?
Both feature keys and hard-corded values are used.
What is the new behavior?
Declared feature keys are being used in all places where they should be referenced which scope potential name changes to one place.
Does this PR introduce a breaking change?
Other information