refactor(router): remove RouteEvent base class (#19043)
* Introduced with #18407, `RouteEvents` don't actually have a common constructor. Reverting here to be able to add new functionality to ChildActivation events. PR Close #19043
This commit is contained in:
		
							parent
							
								
									1a9d382da9
								
							
						
					
					
						commit
						dce36751f5
					
				| @ -35,35 +35,6 @@ export class RouterEvent { | |||||||
|       public url: string) {} |       public url: string) {} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** |  | ||||||
|  * @whatItDoes Base for events tied to a specific `Route`, as opposed to events for the Router |  | ||||||
|  * lifecycle. `RouteEvent`s may be fired multiple times during a single navigation and will |  | ||||||
|  * always receive the `Route` they pertain to. |  | ||||||
|  * |  | ||||||
|  * Example: |  | ||||||
|  * |  | ||||||
|  * ``` |  | ||||||
|  * class MyService { |  | ||||||
|  *   constructor(public router: Router, spinner: Spinner) { |  | ||||||
|  *     router.events.filter(e => e instanceof RouteEvent).subscribe(e => { |  | ||||||
|  *       if (e instanceof ChildActivationStart) { |  | ||||||
|  *         spinner.start(e.route); |  | ||||||
|  *       } else if (e instanceof ChildActivationEnd) { |  | ||||||
|  *         spinner.end(e.route); |  | ||||||
|  *       } |  | ||||||
|  *     }); |  | ||||||
|  *   } |  | ||||||
|  * } |  | ||||||
|  * ``` |  | ||||||
|  * |  | ||||||
|  * @experimental |  | ||||||
|  */ |  | ||||||
| export class RouteEvent { |  | ||||||
|   constructor( |  | ||||||
|       /** @docsNotRequired */ |  | ||||||
|       public route: Route) {} |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** | /** | ||||||
|  * @whatItDoes Represents an event triggered when a navigation starts. |  * @whatItDoes Represents an event triggered when a navigation starts. | ||||||
|  * |  * | ||||||
| @ -265,7 +236,10 @@ export class ResolveEnd extends RouterEvent { | |||||||
|  * |  * | ||||||
|  * @experimental |  * @experimental | ||||||
|  */ |  */ | ||||||
| export class RouteConfigLoadStart extends RouteEvent { | export class RouteConfigLoadStart { | ||||||
|  |   constructor( | ||||||
|  |       /** @docsNotRequired */ | ||||||
|  |       public route: Route) {} | ||||||
|   toString(): string { return `RouteConfigLoadStart(path: ${this.route.path})`; } |   toString(): string { return `RouteConfigLoadStart(path: ${this.route.path})`; } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -274,7 +248,10 @@ export class RouteConfigLoadStart extends RouteEvent { | |||||||
|  * |  * | ||||||
|  * @experimental |  * @experimental | ||||||
|  */ |  */ | ||||||
| export class RouteConfigLoadEnd extends RouteEvent { | export class RouteConfigLoadEnd { | ||||||
|  |   constructor( | ||||||
|  |       /** @docsNotRequired */ | ||||||
|  |       public route: Route) {} | ||||||
|   toString(): string { return `RouteConfigLoadEnd(path: ${this.route.path})`; } |   toString(): string { return `RouteConfigLoadEnd(path: ${this.route.path})`; } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -284,7 +261,10 @@ export class RouteConfigLoadEnd extends RouteEvent { | |||||||
|  * |  * | ||||||
|  * @experimental |  * @experimental | ||||||
|  */ |  */ | ||||||
| export class ChildActivationStart extends RouteEvent { | export class ChildActivationStart { | ||||||
|  |   constructor( | ||||||
|  |       /** @docsNotRequired */ | ||||||
|  |       public route: Route) {} | ||||||
|   toString(): string { return `ChildActivationStart(path: '${this.route.path}')`; } |   toString(): string { return `ChildActivationStart(path: '${this.route.path}')`; } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -294,7 +274,10 @@ export class ChildActivationStart extends RouteEvent { | |||||||
|  * |  * | ||||||
|  * @experimental |  * @experimental | ||||||
|  */ |  */ | ||||||
| export class ChildActivationEnd extends RouteEvent { | export class ChildActivationEnd { | ||||||
|  |   constructor( | ||||||
|  |       /** @docsNotRequired */ | ||||||
|  |       public route: Route) {} | ||||||
|   toString(): string { return `ChildActivationEnd(path: '${this.route.path}')`; } |   toString(): string { return `ChildActivationEnd(path: '${this.route.path}')`; } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -319,4 +302,5 @@ export class ChildActivationEnd extends RouteEvent { | |||||||
|  * |  * | ||||||
|  * @stable |  * @stable | ||||||
|  */ |  */ | ||||||
| export type Event = RouterEvent | RouteEvent; | export type Event = RouterEvent | RouteConfigLoadStart | RouteConfigLoadEnd | ChildActivationStart | | ||||||
|  |     ChildActivationEnd; | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ export {Data, LoadChildren, LoadChildrenCallback, ResolveData, Route, Routes, Ru | |||||||
| export {RouterLink, RouterLinkWithHref} from './directives/router_link'; | export {RouterLink, RouterLinkWithHref} from './directives/router_link'; | ||||||
| export {RouterLinkActive} from './directives/router_link_active'; | export {RouterLinkActive} from './directives/router_link_active'; | ||||||
| export {RouterOutlet} from './directives/router_outlet'; | export {RouterOutlet} from './directives/router_outlet'; | ||||||
| export {ChildActivationEnd, ChildActivationStart, Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouteEvent, RoutesRecognized} from './events'; | export {ChildActivationEnd, ChildActivationStart, Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouterEvent, RoutesRecognized} from './events'; | ||||||
| export {CanActivate, CanActivateChild, CanDeactivate, CanLoad, Resolve} from './interfaces'; | export {CanActivate, CanActivateChild, CanDeactivate, CanLoad, Resolve} from './interfaces'; | ||||||
| export {DetachedRouteHandle, RouteReuseStrategy} from './route_reuse_strategy'; | export {DetachedRouteHandle, RouteReuseStrategy} from './route_reuse_strategy'; | ||||||
| export {NavigationExtras, Router} from './router'; | export {NavigationExtras, Router} from './router'; | ||||||
|  | |||||||
| @ -19,7 +19,7 @@ import {mergeMap} from 'rxjs/operator/mergeMap'; | |||||||
| import {reduce} from 'rxjs/operator/reduce'; | import {reduce} from 'rxjs/operator/reduce'; | ||||||
| 
 | 
 | ||||||
| import {LoadedRouterConfig, ResolveData, RunGuardsAndResolvers} from './config'; | import {LoadedRouterConfig, ResolveData, RunGuardsAndResolvers} from './config'; | ||||||
| import {ChildActivationStart, RouteEvent} from './events'; | import {ChildActivationStart, Event} from './events'; | ||||||
| import {ChildrenOutletContexts, OutletContext} from './router_outlet_context'; | import {ChildrenOutletContexts, OutletContext} from './router_outlet_context'; | ||||||
| import {ActivatedRouteSnapshot, RouterStateSnapshot, equalParamsAndUrlSegments, inheritedParamsDataResolve} from './router_state'; | import {ActivatedRouteSnapshot, RouterStateSnapshot, equalParamsAndUrlSegments, inheritedParamsDataResolve} from './router_state'; | ||||||
| import {andObservables, forEach, shallowEqual, wrapIntoObservable} from './utils/collection'; | import {andObservables, forEach, shallowEqual, wrapIntoObservable} from './utils/collection'; | ||||||
| @ -43,7 +43,7 @@ export class PreActivation { | |||||||
| 
 | 
 | ||||||
|   constructor( |   constructor( | ||||||
|       private future: RouterStateSnapshot, private curr: RouterStateSnapshot, |       private future: RouterStateSnapshot, private curr: RouterStateSnapshot, | ||||||
|       private moduleInjector: Injector, private forwardEvent?: (evt: RouteEvent) => void) {} |       private moduleInjector: Injector, private forwardEvent?: (evt: Event) => void) {} | ||||||
| 
 | 
 | ||||||
|   initalize(parentContexts: ChildrenOutletContexts): void { |   initalize(parentContexts: ChildrenOutletContexts): void { | ||||||
|     const futureRoot = this.future._root; |     const futureRoot = this.future._root; | ||||||
|  | |||||||
| @ -21,7 +21,7 @@ import {applyRedirects} from './apply_redirects'; | |||||||
| import {LoadedRouterConfig, QueryParamsHandling, Route, Routes, validateConfig} from './config'; | import {LoadedRouterConfig, QueryParamsHandling, Route, Routes, validateConfig} from './config'; | ||||||
| import {createRouterState} from './create_router_state'; | import {createRouterState} from './create_router_state'; | ||||||
| import {createUrlTree} from './create_url_tree'; | import {createUrlTree} from './create_url_tree'; | ||||||
| import {ChildActivationEnd, Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouteEvent, RoutesRecognized} from './events'; | import {ChildActivationEnd, Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouterEvent, RoutesRecognized} from './events'; | ||||||
| import {PreActivation} from './pre_activation'; | import {PreActivation} from './pre_activation'; | ||||||
| import {recognize} from './recognize'; | import {recognize} from './recognize'; | ||||||
| import {DefaultRouteReuseStrategy, DetachedRouteHandleInternal, RouteReuseStrategy} from './route_reuse_strategy'; | import {DefaultRouteReuseStrategy, DetachedRouteHandleInternal, RouteReuseStrategy} from './route_reuse_strategy'; | ||||||
| @ -628,7 +628,7 @@ export class Router { | |||||||
|             const moduleInjector = this.ngModule.injector; |             const moduleInjector = this.ngModule.injector; | ||||||
|             preActivation = new PreActivation( |             preActivation = new PreActivation( | ||||||
|                 snapshot, this.currentRouterState.snapshot, moduleInjector, |                 snapshot, this.currentRouterState.snapshot, moduleInjector, | ||||||
|                 (evt: RouteEvent) => this.triggerEvent(evt)); |                 (evt: Event) => this.triggerEvent(evt)); | ||||||
|             preActivation.initalize(this.rootContexts); |             preActivation.initalize(this.rootContexts); | ||||||
|             return {appliedUrl, snapshot}; |             return {appliedUrl, snapshot}; | ||||||
|           }); |           }); | ||||||
| @ -764,7 +764,7 @@ export class Router { | |||||||
| class ActivateRoutes { | class ActivateRoutes { | ||||||
|   constructor( |   constructor( | ||||||
|       private routeReuseStrategy: RouteReuseStrategy, private futureState: RouterState, |       private routeReuseStrategy: RouteReuseStrategy, private futureState: RouterState, | ||||||
|       private currState: RouterState, private forwardEvent: (evt: RouteEvent) => void) {} |       private currState: RouterState, private forwardEvent: (evt: Event) => void) {} | ||||||
| 
 | 
 | ||||||
|   activate(parentContexts: ChildrenOutletContexts): void { |   activate(parentContexts: ChildrenOutletContexts): void { | ||||||
|     const futureRoot = this.futureState._root; |     const futureRoot = this.futureState._root; | ||||||
|  | |||||||
| @ -11,7 +11,7 @@ import {ChangeDetectionStrategy, Component, Injectable, NgModule, NgModuleFactor | |||||||
| import {ComponentFixture, TestBed, fakeAsync, inject, tick} from '@angular/core/testing'; | import {ComponentFixture, TestBed, fakeAsync, inject, tick} from '@angular/core/testing'; | ||||||
| import {By} from '@angular/platform-browser/src/dom/debug/by'; | import {By} from '@angular/platform-browser/src/dom/debug/by'; | ||||||
| import {expect} from '@angular/platform-browser/testing/src/matchers'; | import {expect} from '@angular/platform-browser/testing/src/matchers'; | ||||||
| import {ActivatedRoute, ActivatedRouteSnapshot, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, PRIMARY_OUTLET, ParamMap, Params, PreloadAllModules, PreloadingStrategy, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouteEvent, RouteReuseStrategy, Router, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlTree} from '@angular/router'; | import {ActivatedRoute, ActivatedRouteSnapshot, CanActivate, CanDeactivate, ChildActivationEnd, ChildActivationStart, DetachedRouteHandle, Event, GuardsCheckEnd, GuardsCheckStart, NavigationCancel, NavigationEnd, NavigationError, NavigationStart, PRIMARY_OUTLET, ParamMap, Params, PreloadAllModules, PreloadingStrategy, Resolve, ResolveEnd, ResolveStart, RouteConfigLoadEnd, RouteConfigLoadStart, RouteReuseStrategy, Router, RouterEvent, RouterModule, RouterPreloader, RouterStateSnapshot, RoutesRecognized, RunGuardsAndResolvers, UrlHandlingStrategy, UrlSegmentGroup, UrlTree} from '@angular/router'; | ||||||
| import {Observable} from 'rxjs/Observable'; | import {Observable} from 'rxjs/Observable'; | ||||||
| import {Observer} from 'rxjs/Observer'; | import {Observer} from 'rxjs/Observer'; | ||||||
| import {of } from 'rxjs/observable/of'; | import {of } from 'rxjs/observable/of'; | ||||||
| @ -428,7 +428,7 @@ describe('Integration', () => { | |||||||
|        }]); |        }]); | ||||||
| 
 | 
 | ||||||
|        const recordedEvents: any[] = []; |        const recordedEvents: any[] = []; | ||||||
|        router.events.forEach(e => e instanceof RouteEvent || recordedEvents.push(e)); |        router.events.forEach(e => e instanceof RouterEvent && recordedEvents.push(e)); | ||||||
| 
 | 
 | ||||||
|        router.navigateByUrl('/team/22/user/victor'); |        router.navigateByUrl('/team/22/user/victor'); | ||||||
|        advance(fixture); |        advance(fixture); | ||||||
| @ -986,7 +986,7 @@ describe('Integration', () => { | |||||||
|              [{path: 'simple', component: SimpleCmp, resolve: {error: 'resolveError'}}]); |              [{path: 'simple', component: SimpleCmp, resolve: {error: 'resolveError'}}]); | ||||||
| 
 | 
 | ||||||
|          const recordedEvents: any[] = []; |          const recordedEvents: any[] = []; | ||||||
|          router.events.subscribe(e => e instanceof RouteEvent || recordedEvents.push(e)); |          router.events.subscribe(e => e instanceof RouterEvent && recordedEvents.push(e)); | ||||||
| 
 | 
 | ||||||
|          let e: any = null; |          let e: any = null; | ||||||
|          router.navigateByUrl('/simple') !.catch(error => e = error); |          router.navigateByUrl('/simple') !.catch(error => e = error); | ||||||
| @ -3344,7 +3344,7 @@ describe('Integration', () => { | |||||||
|            }]); |            }]); | ||||||
| 
 | 
 | ||||||
|            const events: any[] = []; |            const events: any[] = []; | ||||||
|            router.events.subscribe(e => e instanceof RouteEvent || events.push(e)); |            router.events.subscribe(e => e instanceof RouterEvent && events.push(e)); | ||||||
| 
 | 
 | ||||||
|            // supported URL
 |            // supported URL
 | ||||||
|            router.navigateByUrl('/include/user/kate'); |            router.navigateByUrl('/include/user/kate'); | ||||||
| @ -3408,7 +3408,7 @@ describe('Integration', () => { | |||||||
|            }]); |            }]); | ||||||
| 
 | 
 | ||||||
|            const events: any[] = []; |            const events: any[] = []; | ||||||
|            router.events.subscribe(e => e instanceof RouteEvent || events.push(e)); |            router.events.subscribe(e => e instanceof RouterEvent && events.push(e)); | ||||||
| 
 | 
 | ||||||
|            location.go('/include/user/kate(aux:excluded)'); |            location.go('/include/user/kate(aux:excluded)'); | ||||||
|            advance(fixture); |            advance(fixture); | ||||||
|  | |||||||
							
								
								
									
										42
									
								
								tools/public_api_guard/router/index.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										42
									
								
								tools/public_api_guard/router/index.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -60,12 +60,18 @@ export interface CanLoad { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @experimental */ | /** @experimental */ | ||||||
| export declare class ChildActivationEnd extends RouteEvent { | export declare class ChildActivationEnd { | ||||||
|  |     route: Route; | ||||||
|  |     constructor( | ||||||
|  |         route: Route); | ||||||
|     toString(): string; |     toString(): string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @experimental */ | /** @experimental */ | ||||||
| export declare class ChildActivationStart extends RouteEvent { | export declare class ChildActivationStart { | ||||||
|  |     route: Route; | ||||||
|  |     constructor( | ||||||
|  |         route: Route); | ||||||
|     toString(): string; |     toString(): string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -97,7 +103,7 @@ export declare class DefaultUrlSerializer implements UrlSerializer { | |||||||
| export declare type DetachedRouteHandle = {}; | export declare type DetachedRouteHandle = {}; | ||||||
| 
 | 
 | ||||||
| /** @stable */ | /** @stable */ | ||||||
| export declare type Event = RouterEvent | RouteEvent; | export declare type Event = RouterEvent | RouteConfigLoadStart | RouteConfigLoadEnd | ChildActivationStart | ChildActivationEnd; | ||||||
| 
 | 
 | ||||||
| /** @stable */ | /** @stable */ | ||||||
| export interface ExtraOptions { | export interface ExtraOptions { | ||||||
| @ -284,20 +290,19 @@ export interface Route { | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @experimental */ | /** @experimental */ | ||||||
| export declare class RouteConfigLoadEnd extends RouteEvent { | export declare class RouteConfigLoadEnd { | ||||||
|     toString(): string; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** @experimental */ |  | ||||||
| export declare class RouteConfigLoadStart extends RouteEvent { |  | ||||||
|     toString(): string; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| /** @experimental */ |  | ||||||
| export declare class RouteEvent { |  | ||||||
|     route: Route; |     route: Route; | ||||||
|     constructor( |     constructor( | ||||||
|         route: Route); |         route: Route); | ||||||
|  |     toString(): string; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | /** @experimental */ | ||||||
|  | export declare class RouteConfigLoadStart { | ||||||
|  |     route: Route; | ||||||
|  |     constructor( | ||||||
|  |         route: Route); | ||||||
|  |     toString(): string; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /** @stable */ | /** @stable */ | ||||||
| @ -339,6 +344,15 @@ export declare abstract class RouteReuseStrategy { | |||||||
|     abstract store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void; |     abstract store(route: ActivatedRouteSnapshot, handle: DetachedRouteHandle | null): void; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /** @experimental */ | ||||||
|  | export declare class RouterEvent { | ||||||
|  |     id: number; | ||||||
|  |     url: string; | ||||||
|  |     constructor( | ||||||
|  |         id: number, | ||||||
|  |         url: string); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /** @stable */ | /** @stable */ | ||||||
| export declare class RouterLink { | export declare class RouterLink { | ||||||
|     fragment: string; |     fragment: string; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user