Skip to content
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

Merged
merged 1 commit into from
Jan 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions projects/example-app/src/app/auth/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const selectAuthState = createFeatureSelector<State, AuthState>(

export const selectAuthStatusState = createSelector(
selectAuthState,
(state: AuthState) => state.status
state => state.status
);
export const selectUser = createSelector(
selectAuthStatusState,
Expand All @@ -42,7 +42,7 @@ export const selectLoggedIn = createSelector(selectUser, user => !!user);

export const selectLoginPageState = createSelector(
selectAuthState,
(state: AuthState) => state.loginPage
state => state.loginPage
);
export const selectLoginPageError = createSelector(
selectLoginPageState,
Expand Down
4 changes: 2 additions & 2 deletions projects/example-app/src/app/books/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export const selectSelectedBook = createSelector(
*/
export const selectSearchState = createSelector(
selectBooksState,
(state: BooksState) => state.search
state => state.search
);

export const selectSearchBookIds = createSelector(
Expand Down Expand Up @@ -139,7 +139,7 @@ export const selectSearchResults = createSelector(

export const selectCollectionState = createSelector(
selectBooksState,
(state: BooksState) => state.collection
state => state.collection
);

export const selectCollectionLoaded = createSelector(
Expand Down
2 changes: 1 addition & 1 deletion projects/example-app/src/app/reducers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const metaReducers: MetaReducer<State>[] = !environment.production
* Layout Reducers
*/
export const selectLayoutState = createFeatureSelector<State, fromLayout.State>(
Copy link
Member

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.

Copy link
Contributor Author

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 ??

Copy link
Member

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.

Copy link
Member

@timdeschryver timdeschryver Jan 23, 2020

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.

Copy link
Member

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

'layout'
fromLayout.layoutFeatureKey
timdeschryver marked this conversation as resolved.
Show resolved Hide resolved
);

export const selecthowSidenav = createSelector(
Expand Down