-
-
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
feat(Router-Store): New actions, config enhancement #1267
Conversation
…rnal router hook, more typesafety for router state
* Simple router state. | ||
* All custom router states / state serializers should have at least this property. | ||
*/ | ||
export interface RouterState { |
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.
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'; | ||
|
||
/** |
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.
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; |
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 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, |
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.
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!(); |
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.
This doesn't support dependencies being injected into the serializer
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.
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?
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 didn't have the time to take this all in, I'll try to get back at this later today.
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.
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 }
],
};
}
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.
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 { |
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.
What about BaseRouterState?
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.
Or BaseRouterStoreState
): RouterStateSerializer { | ||
// This function gets handed a complete config-object from _createRouterConfig, | ||
// so we know the serializer property exists | ||
return new config.serializer!(); |
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.
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 }
Thanks @dummdidumm! |
Hi Brandon, I am having this same issue, with which release is the ROUTER_NAVIGATED action going to be available? Thanks!! |
@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 |
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? |
@jasanst yea it's an unreleased feature. |
Thanks, just getting started so would rather see documentation for the current prod version instead, is this still available? |
@jasanst you can get the latest release on npm through the tag. https://github.com/ngrx/platform/tree/6.1.0 |
@brandonroberts - ETA on next stable release? |
bump |
@brandonroberts Is this fix available in any 6.x.x releases or is it only available in 7.x.x? |
@DonatasD this is available starting from 7.x.x |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
What is the new behavior?
Closes #1010, #975, #1262, #1263
Does this PR introduce a 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:
Other information
I will update the documentation if the changes are approved.