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:
Jason Aden
2017-09-05 11:54:33 -07:00
committed by Miško Hevery
parent 1a9d382da9
commit dce36751f5
6 changed files with 57 additions and 59 deletions

View File

@ -35,35 +35,6 @@ export class RouterEvent {
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.
*
@ -265,7 +236,10 @@ export class ResolveEnd extends RouterEvent {
*
* @experimental
*/
export class RouteConfigLoadStart extends RouteEvent {
export class RouteConfigLoadStart {
constructor(
/** @docsNotRequired */
public route: Route) {}
toString(): string { return `RouteConfigLoadStart(path: ${this.route.path})`; }
}
@ -274,7 +248,10 @@ export class RouteConfigLoadStart extends RouteEvent {
*
* @experimental
*/
export class RouteConfigLoadEnd extends RouteEvent {
export class RouteConfigLoadEnd {
constructor(
/** @docsNotRequired */
public route: Route) {}
toString(): string { return `RouteConfigLoadEnd(path: ${this.route.path})`; }
}
@ -284,7 +261,10 @@ export class RouteConfigLoadEnd extends RouteEvent {
*
* @experimental
*/
export class ChildActivationStart extends RouteEvent {
export class ChildActivationStart {
constructor(
/** @docsNotRequired */
public route: Route) {}
toString(): string { return `ChildActivationStart(path: '${this.route.path}')`; }
}
@ -294,7 +274,10 @@ export class ChildActivationStart extends RouteEvent {
*
* @experimental
*/
export class ChildActivationEnd extends RouteEvent {
export class ChildActivationEnd {
constructor(
/** @docsNotRequired */
public route: Route) {}
toString(): string { return `ChildActivationEnd(path: '${this.route.path}')`; }
}
@ -319,4 +302,5 @@ export class ChildActivationEnd extends RouteEvent {
*
* @stable
*/
export type Event = RouterEvent | RouteEvent;
export type Event = RouterEvent | RouteConfigLoadStart | RouteConfigLoadEnd | ChildActivationStart |
ChildActivationEnd;

View File

@ -11,7 +11,7 @@ export {Data, LoadChildren, LoadChildrenCallback, ResolveData, Route, Routes, Ru
export {RouterLink, RouterLinkWithHref} from './directives/router_link';
export {RouterLinkActive} from './directives/router_link_active';
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 {DetachedRouteHandle, RouteReuseStrategy} from './route_reuse_strategy';
export {NavigationExtras, Router} from './router';

View File

@ -19,7 +19,7 @@ import {mergeMap} from 'rxjs/operator/mergeMap';
import {reduce} from 'rxjs/operator/reduce';
import {LoadedRouterConfig, ResolveData, RunGuardsAndResolvers} from './config';
import {ChildActivationStart, RouteEvent} from './events';
import {ChildActivationStart, Event} from './events';
import {ChildrenOutletContexts, OutletContext} from './router_outlet_context';
import {ActivatedRouteSnapshot, RouterStateSnapshot, equalParamsAndUrlSegments, inheritedParamsDataResolve} from './router_state';
import {andObservables, forEach, shallowEqual, wrapIntoObservable} from './utils/collection';
@ -43,7 +43,7 @@ export class PreActivation {
constructor(
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 {
const futureRoot = this.future._root;

View File

@ -21,7 +21,7 @@ import {applyRedirects} from './apply_redirects';
import {LoadedRouterConfig, QueryParamsHandling, Route, Routes, validateConfig} from './config';
import {createRouterState} from './create_router_state';
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 {recognize} from './recognize';
import {DefaultRouteReuseStrategy, DetachedRouteHandleInternal, RouteReuseStrategy} from './route_reuse_strategy';
@ -628,7 +628,7 @@ export class Router {
const moduleInjector = this.ngModule.injector;
preActivation = new PreActivation(
snapshot, this.currentRouterState.snapshot, moduleInjector,
(evt: RouteEvent) => this.triggerEvent(evt));
(evt: Event) => this.triggerEvent(evt));
preActivation.initalize(this.rootContexts);
return {appliedUrl, snapshot};
});
@ -764,7 +764,7 @@ export class Router {
class ActivateRoutes {
constructor(
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 {
const futureRoot = this.futureState._root;