Skip to content

Commit bd415a1

Browse files
fix(RouterStore): Replace RouterStateSnapshot with SerializedRouterStateSnapshot
BREAKING CHANGE: Default router state is serialized to a shape that removes cycles BEFORE: Full RouterStateSnapshot is returned AFTER: Router state snapshot is returned as a SerializedRouterStateSnapshot with cyclical dependencies removed
1 parent 7917a27 commit bd415a1

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

modules/router-store/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ export {
2121
export {
2222
RouterStateSerializer,
2323
DefaultRouterStateSerializer,
24+
SerializedRouterStateSnapshot,
2425
} from './serializer';

modules/router-store/src/router_store_module.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { of } from 'rxjs';
1717
import {
1818
DefaultRouterStateSerializer,
1919
RouterStateSerializer,
20+
SerializedRouterStateSnapshot,
2021
} from './serializer';
2122

2223
/**
@@ -35,7 +36,7 @@ export type RouterNavigationPayload<T> = {
3536
/**
3637
* An action dispatched when the router navigates.
3738
*/
38-
export type RouterNavigationAction<T = RouterStateSnapshot> = {
39+
export type RouterNavigationAction<T = SerializedRouterStateSnapshot> = {
3940
type: typeof ROUTER_NAVIGATION;
4041
payload: RouterNavigationPayload<T>;
4142
};
@@ -57,7 +58,7 @@ export type RouterCancelPayload<T, V> = {
5758
/**
5859
* An action dispatched when the router cancel navigation.
5960
*/
60-
export type RouterCancelAction<T, V = RouterStateSnapshot> = {
61+
export type RouterCancelAction<T, V = SerializedRouterStateSnapshot> = {
6162
type: typeof ROUTER_CANCEL;
6263
payload: RouterCancelPayload<T, V>;
6364
};
@@ -79,25 +80,25 @@ export type RouterErrorPayload<T, V> = {
7980
/**
8081
* An action dispatched when the router errors.
8182
*/
82-
export type RouterErrorAction<T, V = RouterStateSnapshot> = {
83+
export type RouterErrorAction<T, V = SerializedRouterStateSnapshot> = {
8384
type: typeof ROUTER_ERROR;
8485
payload: RouterErrorPayload<T, V>;
8586
};
8687

8788
/**
8889
* An union type of router actions.
8990
*/
90-
export type RouterAction<T, V = RouterStateSnapshot> =
91+
export type RouterAction<T, V = SerializedRouterStateSnapshot> =
9192
| RouterNavigationAction<V>
9293
| RouterCancelAction<T, V>
9394
| RouterErrorAction<T, V>;
9495

95-
export type RouterReducerState<T = RouterStateSnapshot> = {
96+
export type RouterReducerState<T = SerializedRouterStateSnapshot> = {
9697
state: T;
9798
navigationId: number;
9899
};
99100

100-
export function routerReducer<T = RouterStateSnapshot>(
101+
export function routerReducer<T = SerializedRouterStateSnapshot>(
101102
state: RouterReducerState<T> | undefined,
102103
action: RouterAction<any, T>
103104
): RouterReducerState<T> {
@@ -153,7 +154,7 @@ export type StoreRouterConfigFunction = () => StoreRouterConfig;
153154
*
154155
* ```
155156
* export type RouterNavigationPayload = {
156-
* routerState: RouterStateSnapshot,
157+
* routerState: SerializedRouterStateSnapshot,
157158
* event: RoutesRecognized
158159
* }
159160
* ```
@@ -221,7 +222,7 @@ export class StoreRouterConnectingModule {
221222
};
222223
}
223224

224-
private routerState: RouterStateSnapshot;
225+
private routerState: SerializedRouterStateSnapshot;
225226
private storeState: any;
226227
private lastRoutesRecognized: RoutesRecognized;
227228

@@ -232,7 +233,7 @@ export class StoreRouterConnectingModule {
232233
constructor(
233234
private store: Store<any>,
234235
private router: Router,
235-
private serializer: RouterStateSerializer<RouterStateSnapshot>,
236+
private serializer: RouterStateSerializer<SerializedRouterStateSnapshot>,
236237
@Inject(ROUTER_CONFIG) private config: StoreRouterConfig
237238
) {
238239
this.stateKey = this.config.stateKey as string;

0 commit comments

Comments
 (0)