-
-
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(RouterStore): Added serializer for router state snapshot #188
Conversation
From a quick read of the code, it looks like this keeps the default behavior of sticking the unserializable router state in the State, but makes it possible for an application to avoid that by providing something custom, for example by copying code from the example application. My way-out-here-in-userland perspective is that it would be more helpful if the default serializer did the "Right Thing", so that most applications get a serializable State without effort. I dream of a future where Store runs in a "frozen, enforced serializability" mode by default, and requires a |
@kylecordes I agree that the default should be a slimmed down version of the router state snapshot. It would be a breaking change to the current functionality though, so we'll keep it as is, deprecate it and change the default in the next version. Me and @MikeRyanDev have talked about have a config option out of the box to freeze the state, but it was more of an opt-in approach. We'll revisit that soon for the next version, as we'll need a replacement for |
| Partial<RouterStateSnapshot>; | ||
|
||
export abstract class RouterStateSerializer { | ||
abstract serialize(routerState: RouterStateSnapshotType | null): RouterStateSnapshotType | null; |
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.
why |null
?
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.
Maybe we guard against nulls outside? Cause I think it should never be called with null
.
|
||
export type RouterStateSnapshotType = | ||
| RouterStateSnapshot | ||
| Partial<RouterStateSnapshot>; |
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'm not sure if partial is actually useful there as it it is not recursive and as such you either have to provide the whole root node or 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.
basically the following will fail:
const r: RouterStateSnapshotType;
r.root.params // won't compile
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.
Maybe we can parameterize RouterNavigationAction
instead?
@@ -0,0 +1,15 @@ | |||
import { RouterStateSnapshot } from '@angular/router'; | |||
|
|||
export type RouterStateSnapshotType = |
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.
Not a big fan of the Type
suffix.
Maybe SerializedRouterStateSnapshot
?
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.
Good suggestion
6624adb
to
9a4a26b
Compare
9a4a26b
to
858de40
Compare
@vsavkin this one is ready for another review |
LGTM |
@brandonroberts Thanks for the workaround.
Again thanks for the fix we are back up and running with the nightly build. |
This adds a serializer that can be customized for returning the router state snapshot. By default, the entire RouterStateSnapshot is returned. Documentation has been updated with example usage.
Closes #97, #104, #237