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

feat(router-store): add createRouterSelector to select router data for default config #3103

Merged
merged 3 commits into from
Aug 4, 2021

Conversation

timdeschryver
Copy link
Member

@timdeschryver timdeschryver commented Aug 1, 2021

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Closes #

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

This is an RFC to make it easier to select the router state when the default router config is used.
Because the router store module is opinionated and uses router as the default feature name, I was thinking about adding a bit of default behavior to the current router selectors. This aims to make it easier to get started with using the router store.

When the default config is used, I think we can:

  • export a router state selector
  • make getSelectors smarter and to use the default router state selector to retrieve the router state

I started this PR to promote and use the DEFAULT_ROUTER_FEATURENAME (instead of the "magic router" string) constant in the example app and the docs. But then I continued to make the selectors more opinionated, because this is how I've been and seen using it in all the projects.

BEFORE:

export const selectRouter = createFeatureSelector<fromRouter.RouterReducerState>(
  'router'
);

export const { selectRouteData } = fromRouter.getSelectors(selectRouter);

AFTER:

// change 1, select the default router state with createRouterSelector

export const selectRouter = createRouterSelector();

// change 2, the selector argument of getSelectors isn't required

export const { selectRouteData } = fromRouter.getSelectors();

Copy link
Member

@markostanimirovic markostanimirovic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, Tim 👍 Just a small suggestion:

modules/router-store/src/router_selectors.ts Outdated Show resolved Hide resolved
Co-authored-by: Marko Stanimirović <markostanimirovic95@gmail.com>
@ngrxbot
Copy link
Collaborator

ngrxbot commented Aug 4, 2021

Preview docs changes for 620987c at https://previews.ngrx.io/pr3103-620987c1/

@brandonroberts brandonroberts changed the title RFC: feat(router-store): make it easier to select router data for default config feat(router-store): make it easier to select router data for default config Aug 4, 2021
@brandonroberts brandonroberts changed the title feat(router-store): make it easier to select router data for default config feat(router-store): add createRouterSelector to select router data for default config Aug 4, 2021
@brandonroberts brandonroberts merged commit 507f58e into master Aug 4, 2021
@brandonroberts brandonroberts deleted the use-DEFAULT_ROUTER_FEATURENAME branch August 4, 2021 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants