Skip to content

Commit

Permalink
fix(RouterStore): Replace RouterStateSnapshot with SerializedRouterSt…
Browse files Browse the repository at this point in the history
…ateSnapshot

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
  • Loading branch information
brandonroberts committed Mar 30, 2018
1 parent 7917a27 commit bd415a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions modules/router-store/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ export {
export {
RouterStateSerializer,
DefaultRouterStateSerializer,
SerializedRouterStateSnapshot,
} from './serializer';
19 changes: 10 additions & 9 deletions modules/router-store/src/router_store_module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { of } from 'rxjs';
import {
DefaultRouterStateSerializer,
RouterStateSerializer,
SerializedRouterStateSnapshot,
} from './serializer';

/**
Expand All @@ -35,7 +36,7 @@ export type RouterNavigationPayload<T> = {
/**
* An action dispatched when the router navigates.
*/
export type RouterNavigationAction<T = RouterStateSnapshot> = {
export type RouterNavigationAction<T = SerializedRouterStateSnapshot> = {
type: typeof ROUTER_NAVIGATION;
payload: RouterNavigationPayload<T>;
};
Expand All @@ -57,7 +58,7 @@ export type RouterCancelPayload<T, V> = {
/**
* An action dispatched when the router cancel navigation.
*/
export type RouterCancelAction<T, V = RouterStateSnapshot> = {
export type RouterCancelAction<T, V = SerializedRouterStateSnapshot> = {
type: typeof ROUTER_CANCEL;
payload: RouterCancelPayload<T, V>;
};
Expand All @@ -79,25 +80,25 @@ export type RouterErrorPayload<T, V> = {
/**
* An action dispatched when the router errors.
*/
export type RouterErrorAction<T, V = RouterStateSnapshot> = {
export type RouterErrorAction<T, V = SerializedRouterStateSnapshot> = {
type: typeof ROUTER_ERROR;
payload: RouterErrorPayload<T, V>;
};

/**
* An union type of router actions.
*/
export type RouterAction<T, V = RouterStateSnapshot> =
export type RouterAction<T, V = SerializedRouterStateSnapshot> =
| RouterNavigationAction<V>
| RouterCancelAction<T, V>
| RouterErrorAction<T, V>;

export type RouterReducerState<T = RouterStateSnapshot> = {
export type RouterReducerState<T = SerializedRouterStateSnapshot> = {
state: T;
navigationId: number;
};

export function routerReducer<T = RouterStateSnapshot>(
export function routerReducer<T = SerializedRouterStateSnapshot>(
state: RouterReducerState<T> | undefined,
action: RouterAction<any, T>
): RouterReducerState<T> {
Expand Down Expand Up @@ -153,7 +154,7 @@ export type StoreRouterConfigFunction = () => StoreRouterConfig;
*
* ```
* export type RouterNavigationPayload = {
* routerState: RouterStateSnapshot,
* routerState: SerializedRouterStateSnapshot,
* event: RoutesRecognized
* }
* ```
Expand Down Expand Up @@ -221,7 +222,7 @@ export class StoreRouterConnectingModule {
};
}

private routerState: RouterStateSnapshot;
private routerState: SerializedRouterStateSnapshot;
private storeState: any;
private lastRoutesRecognized: RoutesRecognized;

Expand All @@ -232,7 +233,7 @@ export class StoreRouterConnectingModule {
constructor(
private store: Store<any>,
private router: Router,
private serializer: RouterStateSerializer<RouterStateSnapshot>,
private serializer: RouterStateSerializer<SerializedRouterStateSnapshot>,
@Inject(ROUTER_CONFIG) private config: StoreRouterConfig
) {
this.stateKey = this.config.stateKey as string;
Expand Down

0 comments on commit bd415a1

Please sign in to comment.