Content-Length: 450942 | pFad | http://github.com/Rohit-byt/angular-open/commit/72dd1330f22127e7b3b5e2a0ae7b0bc30c080814

FC refactor(router): Use `NavigationTrigger` more consistently and move … · Rohit-byt/angular-open@72dd133 · GitHub
Skip to content

Commit 72dd133

Browse files
atscottkirjs
authored andcommitted
refactor(router): Use NavigationTrigger more consistently and move events helper next to definitions (angular#60736)
This adjusts code to use `NavigationTrigger` type where appropriate and moves the `isPublicRouterEvent` next to the private event type union to make it more obvious that it should be updated along with any updates to the private type union. PR Close angular#60736
1 parent 1522e6c commit 72dd133

File tree

5 files changed

+10
-21
lines changed

5 files changed

+10
-21
lines changed

goldens/public-api/router/index.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ export interface Navigation {
408408
id: number;
409409
initialUrl: UrlTree;
410410
previousNavigation: Navigation | null;
411-
trigger: 'imperative' | 'popstate' | 'hashchange';
411+
trigger: NavigationTrigger;
412412
}
413413

414414
// @public

packages/router/src/events.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,9 @@ export class RedirectRequest {
624624
) {}
625625
}
626626
export type PrivateRouterEvents = BeforeActivateRoutes | RedirectRequest;
627+
export function isPublicRouterEvent(e: Event | PrivateRouterEvents): e is Event {
628+
return !(e instanceof BeforeActivateRoutes) && !(e instanceof RedirectRequest);
629+
}
627630

628631
/**
629632
* Router events that allow you to track the lifecycle of the router.

packages/router/src/navigation_transition.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,8 @@ export interface Navigation {
281281
targetRouterState?: RouterState;
282282
/**
283283
* Identifies how this navigation was triggered.
284-
*
285-
* * 'imperative'--Triggered by `router.navigateByUrl` or `router.navigate`.
286-
* * 'popstate'--Triggered by a popstate event.
287-
* * 'hashchange'--Triggered by a hashchange event.
288284
*/
289-
trigger: 'imperative' | 'popstate' | 'hashchange';
285+
trigger: NavigationTrigger;
290286
/**
291287
* Options that controlled the strategy used for this navigation.
292288
* See `NavigationExtras`.

packages/router/src/router.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,13 @@ import {createSegmentGroupFromRoute, createUrlTreeFromSegmentGroup} from './crea
2323
import {INPUT_BINDER} from './directives/router_outlet';
2424
import {RuntimeErrorCode} from './errors';
2525
import {
26-
BeforeActivateRoutes,
2726
Event,
2827
IMPERATIVE_NAVIGATION,
28+
isPublicRouterEvent,
2929
NavigationCancel,
3030
NavigationCancellationCode,
3131
NavigationEnd,
3232
NavigationTrigger,
33-
PrivateRouterEvents,
3433
RedirectRequest,
3534
} from './events';
3635
import {NavigationBehaviorOptions, OnSameUrlNavigation, Routes} from './models';
@@ -686,7 +685,3 @@ function validateCommands(commands: string[]): void {
686685
}
687686
}
688687
}
689-
690-
function isPublicRouterEvent(e: Event | PrivateRouterEvents): e is Event {
691-
return !(e instanceof BeforeActivateRoutes) && !(e instanceof RedirectRequest);
692-
}

packages/router/src/router_scroller.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@
77
*/
88

99
import {ViewportScroller} from '@angular/common';
10-
import {
11-
EnvironmentInjector,
12-
inject,
13-
Injectable,
14-
InjectionToken,
15-
NgZone,
16-
OnDestroy,
17-
} from '@angular/core';
10+
import {Injectable, InjectionToken, NgZone, OnDestroy} from '@angular/core';
1811
import {Unsubscribable} from 'rxjs';
1912

2013
import {
14+
IMPERATIVE_NAVIGATION,
2115
NavigationEnd,
2216
NavigationSkipped,
2317
NavigationSkippedCode,
2418
NavigationStart,
19+
NavigationTrigger,
2520
Scroll,
2621
} from './events';
2722
import {NavigationTransitions} from './navigation_transition';
@@ -35,7 +30,7 @@ export class RouterScroller implements OnDestroy {
3530
private scrollEventsSubscription?: Unsubscribable;
3631

3732
private lastId = 0;
38-
private lastSource: 'imperative' | 'popstate' | 'hashchange' | undefined = 'imperative';
33+
private lastSource: NavigationTrigger | undefined = IMPERATIVE_NAVIGATION;
3934
private restoredId = 0;
4035
private store: {[key: string]: [number, number]} = {};
4136

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/Rohit-byt/angular-open/commit/72dd1330f22127e7b3b5e2a0ae7b0bc30c080814

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy