Skip to content

Commit 44b1d0c

Browse files
authored
refactor: replace external StrictRouteData with simple type (#326)
Closes #328. ### Refactors - Rename `StrictRouteData` to `InternalStrictRouteData` and use it internally to enforce compatibility with Angular's `Data` type - Replace the exposed `StrictRouteData` with a simple type
2 parents f7ea0d7 + 807b447 commit 44b1d0c

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

packages/router-component-store/src/lib/@ngrx/router-store/minimal_serializer.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import {
2828
Data,
2929
RouterStateSnapshot,
3030
} from '@angular/router';
31+
import { InternalStrictRouteData } from '../../internal-strict-route-data';
3132
import { InternalStrictRouteParams } from '../../internal-strict-route-params';
32-
import { StrictRouteData } from '../../strict-route-data';
3333
import { MinimalActivatedRouteSnapshot } from './minimal-activated-route-state-snapshot';
3434
import { MinimalRouterStateSnapshot } from './minimal-router-state-snapshot';
3535

@@ -44,7 +44,7 @@ export class MinimalRouterStateSerializer {
4444
};
4545
}
4646

47-
#serializeRouteData(routeData: Data): StrictRouteData {
47+
#serializeRouteData(routeData: Data): InternalStrictRouteData {
4848
return Object.fromEntries(Object.entries(routeData));
4949
}
5050

@@ -56,7 +56,9 @@ export class MinimalRouterStateSerializer {
5656
);
5757
return {
5858
params: routeSnapshot.params as InternalStrictRouteParams,
59-
data: this.#serializeRouteData(routeSnapshot.data),
59+
data: this.#serializeRouteData(
60+
routeSnapshot.data
61+
) as InternalStrictRouteData,
6062
url: routeSnapshot.url,
6163
outlet: routeSnapshot.outlet,
6264
title: routeSnapshot.title,

packages/router-component-store/src/lib/global-router-store/global-router-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ import { MinimalActivatedRouteSnapshot } from '../@ngrx/router-store/minimal-act
1414
import { MinimalRouterStateSnapshot } from '../@ngrx/router-store/minimal-router-state-snapshot';
1515
import { MinimalRouterStateSerializer } from '../@ngrx/router-store/minimal_serializer';
1616
import { filterRouterEvents } from '../filter-router-event.operator';
17+
import { InternalStrictRouteData } from '../internal-strict-route-data';
1718
import { InternalStrictRouteParams } from '../internal-strict-route-params';
1819
import { RouterStore } from '../router-store';
19-
import { StrictRouteData } from '../strict-route-data';
2020

2121
interface GlobalRouterState {
2222
readonly routerState: MinimalRouterStateSnapshot;
@@ -56,7 +56,7 @@ export class GlobalRouterStore
5656
this.#rootRoute$,
5757
(route) => route.queryParams
5858
);
59-
routeData$: Observable<StrictRouteData> = this.select(
59+
routeData$: Observable<InternalStrictRouteData> = this.select(
6060
this.currentRoute$,
6161
(route) => route.data
6262
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { Data } from '@angular/router';
2+
import { OmitSymbolIndex } from './util-types/omit-symbol-index';
3+
import { StrictNoAny } from './util-types/strict-no-any';
4+
5+
/**
6+
* @remarks We use this type to ensure compatibility with {@link Data}.
7+
* @internal
8+
*/
9+
export type InternalStrictRouteData = Readonly<
10+
StrictNoAny<OmitSymbolIndex<Data>>
11+
>;

packages/router-component-store/src/lib/local-router-store/local-router-store.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import { MinimalActivatedRouteSnapshot } from '../@ngrx/router-store/minimal-act
1717
import { MinimalRouterStateSnapshot } from '../@ngrx/router-store/minimal-router-state-snapshot';
1818
import { MinimalRouterStateSerializer } from '../@ngrx/router-store/minimal_serializer';
1919
import { filterRouterEvents } from '../filter-router-event.operator';
20+
import { InternalStrictRouteData } from '../internal-strict-route-data';
2021
import { InternalStrictRouteParams } from '../internal-strict-route-params';
2122
import { RouterStore } from '../router-store';
22-
import { StrictRouteData } from '../strict-route-data';
2323

2424
interface LocalRouterState {
2525
readonly routerState: MinimalRouterStateSnapshot;
@@ -45,7 +45,7 @@ export class LocalRouterStore
4545
currentRoute$: Observable<MinimalActivatedRouteSnapshot> = this.#localRoute;
4646
fragment$: Observable<string | null>;
4747
queryParams$: Observable<InternalStrictRouteParams>;
48-
routeData$: Observable<StrictRouteData>;
48+
routeData$: Observable<InternalStrictRouteData>;
4949
routeParams$: Observable<InternalStrictRouteParams>;
5050
title$: Observable<string | undefined>;
5151
url$: Observable<string> = this.select(
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
import { Data } from '@angular/router';
2-
import { OmitSymbolIndex } from './util-types/omit-symbol-index';
3-
import { StrictNoAny } from './util-types/strict-no-any';
4-
51
/**
62
* Serializable route `Data` without its symbol index, in particular without the
73
* `Symbol(RouteTitle)` key as this is an internal value for the Angular
84
* `Router`.
95
*
106
* Additionally, the `any` member type is converted to `unknown`.
117
*/
12-
export type StrictRouteData = Readonly<StrictNoAny<OmitSymbolIndex<Data>>>;
8+
export interface StrictRouteData {
9+
readonly [key: string]: unknown;
10+
}

0 commit comments

Comments
 (0)