Skip to content
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

refactor: replace external StrictRouteParams with simple type #325

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Data,
RouterStateSnapshot,
} from '@angular/router';
import { InternalStrictRouteParams } from '../../internal-strict-route-params';
import { StrictRouteData } from '../../strict-route-data';
import { MinimalActivatedRouteSnapshot } from './minimal-activated-route-state-snapshot';
import { MinimalRouterStateSnapshot } from './minimal-router-state-snapshot';
Expand All @@ -54,7 +55,7 @@ export class MinimalRouterStateSerializer {
this.#serializeRouteSnapshot(childRouteSnapshot)
);
return {
params: routeSnapshot.params,
params: routeSnapshot.params as InternalStrictRouteParams,
data: this.#serializeRouteData(routeSnapshot.data),
url: routeSnapshot.url,
outlet: routeSnapshot.outlet,
Expand All @@ -71,7 +72,7 @@ export class MinimalRouterStateSerializer {
: undefined,
}
: null,
queryParams: routeSnapshot.queryParams,
queryParams: routeSnapshot.queryParams as InternalStrictRouteParams,
fragment: routeSnapshot.fragment,
firstChild: children[0],
children,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import { MinimalActivatedRouteSnapshot } from '../@ngrx/router-store/minimal-act
import { MinimalRouterStateSnapshot } from '../@ngrx/router-store/minimal-router-state-snapshot';
import { MinimalRouterStateSerializer } from '../@ngrx/router-store/minimal_serializer';
import { filterRouterEvents } from '../filter-router-event.operator';
import { InternalStrictRouteParams } from '../internal-strict-route-params';
import { RouterStore } from '../router-store';
import { StrictRouteData } from '../strict-route-data';
import { StrictRouteParams } from '../strict-route-params';

interface GlobalRouterState {
readonly routerState: MinimalRouterStateSnapshot;
Expand Down Expand Up @@ -52,15 +52,15 @@ export class GlobalRouterStore
this.#rootRoute$,
(route) => route.fragment
);
queryParams$: Observable<StrictRouteParams> = this.select(
queryParams$: Observable<InternalStrictRouteParams> = this.select(
this.#rootRoute$,
(route) => route.queryParams
);
routeData$: Observable<StrictRouteData> = this.select(
this.currentRoute$,
(route) => route.data
);
routeParams$: Observable<StrictRouteParams> = this.select(
routeParams$: Observable<InternalStrictRouteParams> = this.select(
this.currentRoute$,
(route) => route.params
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Params } from '@angular/router';
import { StrictNoAny } from './util-types/strict-no-any';

/**
* @remarks We use this type to ensure compatibility with {@link Params}.
* @internal
*/
export type InternalStrictRouteParams = Readonly<
StrictNoAny<Params, string | undefined>
>;
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import { MinimalActivatedRouteSnapshot } from '../@ngrx/router-store/minimal-act
import { MinimalRouterStateSnapshot } from '../@ngrx/router-store/minimal-router-state-snapshot';
import { MinimalRouterStateSerializer } from '../@ngrx/router-store/minimal_serializer';
import { filterRouterEvents } from '../filter-router-event.operator';
import { InternalStrictRouteParams } from '../internal-strict-route-params';
import { RouterStore } from '../router-store';
import { StrictRouteData } from '../strict-route-data';
import { StrictRouteParams } from '../strict-route-params';

interface LocalRouterState {
readonly routerState: MinimalRouterStateSnapshot;
Expand All @@ -44,9 +44,9 @@ export class LocalRouterStore

currentRoute$: Observable<MinimalActivatedRouteSnapshot> = this.#localRoute;
fragment$: Observable<string | null>;
queryParams$: Observable<StrictRouteParams>;
queryParams$: Observable<InternalStrictRouteParams>;
routeData$: Observable<StrictRouteData>;
routeParams$: Observable<StrictRouteParams>;
routeParams$: Observable<InternalStrictRouteParams>;
title$: Observable<string | undefined>;
url$: Observable<string> = this.select(
this.#routerState$,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { Params } from '@angular/router';
import { StrictNoAny } from './util-types/strict-no-any';

/**
* Strict route {@link Params} with read-only members where the `any` member
* type is converted to `string | undefined`.
*/
export type StrictRouteParams = Readonly<
StrictNoAny<Params, string | undefined>
>;
export interface StrictRouteParams {
readonly [param: string]: string | undefined;
}
Loading