Skip to content

Commit 5a236f1

Browse files
committed
refactor: extract router sequence types and type guard
1 parent b1807a0 commit 5a236f1

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ import { ComponentStore, provideComponentStore } from '@ngrx/component-store';
1717
import { filter, map, Observable, switchMap, take } from 'rxjs';
1818
import { filterRouterEvents } from '../filter-router-event.operator';
1919
import { isPopstateNavigationStart } from './popstate-navigation-start';
20+
import {
21+
isRouterNavigatedSequence,
22+
RouterNavigatedSequence,
23+
RouterSequence,
24+
} from './router-sequence';
2025

2126
interface RouterHistoryState {
2227
/**
@@ -31,18 +36,7 @@ interface RouterHistoryState {
3136
readonly maxNavigatedId?: number;
3237
}
3338

34-
type RouterNavigatedSequence = readonly [NavigationStart, NavigationEnd];
3539
type RouterNavigatedHistory = Readonly<Record<number, RouterNavigatedSequence>>;
36-
type RouterSequence = readonly [
37-
NavigationStart,
38-
NavigationEnd | NavigationCancel | NavigationError
39-
];
40-
41-
function isRouterNavigatedSequence(
42-
sequence: RouterSequence
43-
): sequence is RouterNavigatedSequence {
44-
return sequence[1] instanceof NavigationEnd;
45-
}
4640

4741
/**
4842
* Provide and initialize the `RouterHistoryStore`.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {
2+
NavigationCancel,
3+
NavigationEnd,
4+
NavigationError,
5+
NavigationStart,
6+
} from '@angular/router';
7+
8+
export type RouterNavigatedSequence = readonly [NavigationStart, NavigationEnd];
9+
export type RouterSequence = readonly [
10+
NavigationStart,
11+
NavigationEnd | NavigationCancel | NavigationError
12+
];
13+
14+
export function isRouterNavigatedSequence(
15+
sequence: RouterSequence
16+
): sequence is RouterNavigatedSequence {
17+
return sequence[1] instanceof NavigationEnd;
18+
}

0 commit comments

Comments
 (0)