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): New actions, config enhancement #1267

Merged
merged 8 commits into from
Aug 24, 2018

Conversation

dummdidumm
Copy link
Contributor

@dummdidumm dummdidumm commented Aug 21, 2018

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)
[x] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[x] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

What is the new behavior?

Closes #1010, #975, #1262, #1263

  • New actions ROUTER_REQUEST and ROUTER_NAVIGATED that are dispatched at the very start/end of the navigation cycle
  • ROUTER_NAVIGATION action can now be configured to be dispatched after guards and resolvers
  • Custom router state serializer can now be passed as part of config
  • Internals: No longer using internal Angular router hook, instead official router events

Does this PR introduce a breaking change?

[x] Yes
[] No

StoreRouterConfigFunction is removed. It is no longer possible to pass a function returning a StoreRouterConfig to StoreRouterConnectingModule.forRoot

If you still need this, pass a provider like this:

{
      provide: ROUTER_CONFIG,
      useFactory: _createRouterConfig // your function
}

Other information

I will update the documentation if the changes are approved.

@coveralls
Copy link

coveralls commented Aug 21, 2018

Coverage Status

Coverage increased (+0.2%) to 88.769% when pulling 329b0b8 on dummdidumm:feature/router into 4223ff9 on ngrx:master.

* Simple router state.
* All custom router states / state serializers should have at least this property.
*/
export interface RouterState {
Copy link
Member

Choose a reason for hiding this comment

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

This interface needs a different name as the @angular/router already exposes a RouterState. It also needs to be added to src/index.ts

} from './serializer';

/**
Copy link
Member

Choose a reason for hiding this comment

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

These new exports need to be added to src/index.ts

* there may be a navigation cancel due to a guard saying the navigation is not allowed.
* To run ROUTER_NAVIGATION after guards and resolvers, set this property to true.
*/
dispatchNavActionOnEnd?: boolean;
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 this should be more flexible.

enum NavigationAction {
  PreActivation = 1,
  PostActivation = 2
};

navigationAction?: NavigationAction

The default would be PreActivation

export type StoreRouterConfigFunction = () => StoreRouterConfig;

enum RouterTrigger {
NONE,
Copy link
Member

Choose a reason for hiding this comment

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

Provide explicit values

): RouterStateSerializer {
// This function gets handed a complete config-object from _createRouterConfig,
// so we know the serializer property exists
return new config.serializer!();
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't support dependencies being injected into the serializer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this even possible without jumping through fire hoops? The problem is that we don't know the dependencies, so we somehow have to get them dynamically. But to my knowledge, getting these and making sure they exist (and those who are transitively required, too) is not really supported by Angular through some public API. It is only supported to statically define the dependencies.

So we would end up either using Angular internals which is brittle, or write the DI-mechanisms again.

If this is not really possible, maybe we should ditch the serializer option..

@timdeschryver any ideas?

Copy link
Member

Choose a reason for hiding this comment

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

I didn't have the time to take this all in, I'll try to get back at this later today.

Copy link
Member

@brandonroberts brandonroberts Aug 22, 2018

Choose a reason for hiding this comment

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

It's already being injected in the constructor, which will resolve its dependencies. Just use the config to tell it which one to provide. Remove the StoreRouterConfigFunction and move all the providers into the forRoot method. It will be breaking, but more consistent

  static forRoot(
    config: StoreRouterConfig = {}
  ): ModuleWithProviders {
    return {
      ngModule: StoreRouterConnectingModule,
      providers: [
          { provide: _ROUTER_CONFIG, useValue: config },
          { provide: RouterStateSerializer, useClass: config.serializer ? config.serializer : DefaultRouterStateSerializer }
     ],
    };
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok when there is no function to execute it will work (with AOT, too).

* Simple router state.
* All custom router states / state serializers should have at least this property.
*/
export interface SimpleRouterState {
Copy link
Member

Choose a reason for hiding this comment

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

What about BaseRouterState?

Copy link
Member

Choose a reason for hiding this comment

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

Or BaseRouterStoreState

): RouterStateSerializer {
// This function gets handed a complete config-object from _createRouterConfig,
// so we know the serializer property exists
return new config.serializer!();
Copy link
Member

@brandonroberts brandonroberts Aug 22, 2018

Choose a reason for hiding this comment

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

It's already being injected in the constructor, which will resolve its dependencies. Just use the config to tell it which one to provide. Remove the StoreRouterConfigFunction and move all the providers into the forRoot method. It will be breaking, but more consistent

  static forRoot(
    config: StoreRouterConfig = {}
  ): ModuleWithProviders {
    return {
      ngModule: StoreRouterConnectingModule,
      providers: [
          { provide: _ROUTER_CONFIG, useValue: config },
          { provide: RouterStateSerializer, useClass: config.serializer ? config.serializer : DefaultRouterStateSerializer }
     ],
    };
  }

BREAKING CHANGE:

StoreRouterConfigFunction is removed. It is no longer possible to pass a function returning a StoreRouterConfig to StoreRouterConnectingModule.forRoot

If you still need this, pass a provider like this:
{
      provide: ROUTER_CONFIG,
      useFactory: _createRouterConfig // you function
}
@brandonroberts brandonroberts merged commit 8a5e041 into ngrx:master Aug 24, 2018
@brandonroberts
Copy link
Member

Thanks @dummdidumm!

@sbkpilot1
Copy link

sbkpilot1 commented Aug 28, 2018

Hi Brandon, I am having this same issue, with which release is the ROUTER_NAVIGATED action going to be available? Thanks!!

@brandonroberts
Copy link
Member

@sbkpilot1 it won't go out until the next release, which isn't ready yet. If you want to use it now you'll need to use the nightly builds

@jasanst
Copy link

jasanst commented Sep 4, 2018

Did the documentation get released before the functionality?

I'm having trouble using the serializer in StoreRouterConnectingModule.forRoot as shown in the api - it doesn't seem to exist yet?

@timdeschryver
Copy link
Member

@jasanst yea it's an unreleased feature.
If you want you can install the packages from the nightly builds.

@jasanst
Copy link

jasanst commented Sep 5, 2018

Thanks, just getting started so would rather see documentation for the current prod version instead, is this still available?

@brandonroberts
Copy link
Member

@jasanst you can get the latest release on npm through the tag. https://github.com/ngrx/platform/tree/6.1.0

@kellymarjorie
Copy link

@brandonroberts - ETA on next stable release?

@sadsa
Copy link

sadsa commented Nov 19, 2018

bump

@DonatasD
Copy link

DonatasD commented Jan 22, 2019

@brandonroberts Is this fix available in any 6.x.x releases or is it only available in 7.x.x?

@timdeschryver
Copy link
Member

@DonatasD this is available starting from 7.x.x

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.

RFC: RouterStore changes & enhancements
9 participants