refactor(core): remove getters for packages/animations, language-service, platform-browser, router (#19151)
PR Close #19151
This commit is contained in:
parent
17eaef0311
commit
549f2254b4
|
@ -1305,7 +1305,7 @@ export class TransitionAnimationPlayer implements AnimationPlayer {
|
|||
private _containsRealPlayer = false;
|
||||
|
||||
private _queuedCallbacks: {[name: string]: (() => any)[]} = {};
|
||||
private _destroyed = false;
|
||||
public readonly destroyed = false;
|
||||
public parentPlayer: AnimationPlayer;
|
||||
|
||||
public markedForDestroy: boolean = false;
|
||||
|
@ -1314,8 +1314,6 @@ export class TransitionAnimationPlayer implements AnimationPlayer {
|
|||
|
||||
get queued() { return this._containsRealPlayer == false; }
|
||||
|
||||
get destroyed() { return this._destroyed; }
|
||||
|
||||
setRealPlayer(player: AnimationPlayer) {
|
||||
if (this._containsRealPlayer) return;
|
||||
|
||||
|
@ -1368,7 +1366,7 @@ export class TransitionAnimationPlayer implements AnimationPlayer {
|
|||
finish(): void { this._player.finish(); }
|
||||
|
||||
destroy(): void {
|
||||
this._destroyed = true;
|
||||
(this as{destroyed: boolean}).destroyed = true;
|
||||
this._player.destroy();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ export class WebAnimationsPlayer implements AnimationPlayer {
|
|||
private _onDoneFns: Function[] = [];
|
||||
private _onStartFns: Function[] = [];
|
||||
private _onDestroyFns: Function[] = [];
|
||||
private _player: DOMAnimation;
|
||||
private _duration: number;
|
||||
private _delay: number;
|
||||
private _initialized = false;
|
||||
|
@ -23,6 +22,8 @@ export class WebAnimationsPlayer implements AnimationPlayer {
|
|||
private _started = false;
|
||||
private _destroyed = false;
|
||||
private _finalKeyframe: {[key: string]: string | number};
|
||||
|
||||
public readonly domPlayer: DOMAnimation;
|
||||
public time = 0;
|
||||
|
||||
public parentPlayer: AnimationPlayer|null = null;
|
||||
|
@ -86,9 +87,10 @@ export class WebAnimationsPlayer implements AnimationPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
this._player = this._triggerWebAnimation(this.element, keyframes, this.options);
|
||||
(this as{domPlayer: DOMAnimation}).domPlayer =
|
||||
this._triggerWebAnimation(this.element, keyframes, this.options);
|
||||
this._finalKeyframe = keyframes.length ? keyframes[keyframes.length - 1] : {};
|
||||
this._player.addEventListener('finish', () => this._onFinish());
|
||||
this.domPlayer.addEventListener('finish', () => this._onFinish());
|
||||
}
|
||||
|
||||
private _preparePlayerBeforeStart() {
|
||||
|
@ -96,7 +98,7 @@ export class WebAnimationsPlayer implements AnimationPlayer {
|
|||
if (this._delay) {
|
||||
this._resetDomPlayerState();
|
||||
} else {
|
||||
this._player.pause();
|
||||
this.domPlayer.pause();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,8 +109,6 @@ export class WebAnimationsPlayer implements AnimationPlayer {
|
|||
return element['animate'](keyframes, options) as DOMAnimation;
|
||||
}
|
||||
|
||||
get domPlayer() { return this._player; }
|
||||
|
||||
onStart(fn: () => void): void { this._onStartFns.push(fn); }
|
||||
|
||||
onDone(fn: () => void): void { this._onDoneFns.push(fn); }
|
||||
|
@ -122,18 +122,18 @@ export class WebAnimationsPlayer implements AnimationPlayer {
|
|||
this._onStartFns = [];
|
||||
this._started = true;
|
||||
}
|
||||
this._player.play();
|
||||
this.domPlayer.play();
|
||||
}
|
||||
|
||||
pause(): void {
|
||||
this.init();
|
||||
this._player.pause();
|
||||
this.domPlayer.pause();
|
||||
}
|
||||
|
||||
finish(): void {
|
||||
this.init();
|
||||
this._onFinish();
|
||||
this._player.finish();
|
||||
this.domPlayer.finish();
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
|
@ -144,8 +144,8 @@ export class WebAnimationsPlayer implements AnimationPlayer {
|
|||
}
|
||||
|
||||
private _resetDomPlayerState() {
|
||||
if (this._player) {
|
||||
this._player.cancel();
|
||||
if (this.domPlayer) {
|
||||
this.domPlayer.cancel();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,9 +166,9 @@ export class WebAnimationsPlayer implements AnimationPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
setPosition(p: number): void { this._player.currentTime = p * this.time; }
|
||||
setPosition(p: number): void { this.domPlayer.currentTime = p * this.time; }
|
||||
|
||||
getPosition(): number { return this._player.currentTime / this.time; }
|
||||
getPosition(): number { return this.domPlayer.currentTime / this.time; }
|
||||
|
||||
get totalTime(): number { return this._delay + this._duration; }
|
||||
|
||||
|
|
|
@ -19,17 +19,19 @@ export class AnimationGroupPlayer implements AnimationPlayer {
|
|||
|
||||
public parentPlayer: AnimationPlayer|null = null;
|
||||
public totalTime: number = 0;
|
||||
public readonly players: AnimationPlayer[];
|
||||
|
||||
constructor(private _players: AnimationPlayer[]) {
|
||||
constructor(_players: AnimationPlayer[]) {
|
||||
this.players = _players;
|
||||
let doneCount = 0;
|
||||
let destroyCount = 0;
|
||||
let startCount = 0;
|
||||
const total = this._players.length;
|
||||
const total = this.players.length;
|
||||
|
||||
if (total == 0) {
|
||||
scheduleMicroTask(() => this._onFinish());
|
||||
} else {
|
||||
this._players.forEach(player => {
|
||||
this.players.forEach(player => {
|
||||
player.parentPlayer = this;
|
||||
player.onDone(() => {
|
||||
if (++doneCount >= total) {
|
||||
|
@ -49,7 +51,7 @@ export class AnimationGroupPlayer implements AnimationPlayer {
|
|||
});
|
||||
}
|
||||
|
||||
this.totalTime = this._players.reduce((time, player) => Math.max(time, player.totalTime), 0);
|
||||
this.totalTime = this.players.reduce((time, player) => Math.max(time, player.totalTime), 0);
|
||||
}
|
||||
|
||||
private _onFinish() {
|
||||
|
@ -60,7 +62,7 @@ export class AnimationGroupPlayer implements AnimationPlayer {
|
|||
}
|
||||
}
|
||||
|
||||
init(): void { this._players.forEach(player => player.init()); }
|
||||
init(): void { this.players.forEach(player => player.init()); }
|
||||
|
||||
onStart(fn: () => void): void { this._onStartFns.push(fn); }
|
||||
|
||||
|
@ -83,16 +85,16 @@ export class AnimationGroupPlayer implements AnimationPlayer {
|
|||
this.init();
|
||||
}
|
||||
this._onStart();
|
||||
this._players.forEach(player => player.play());
|
||||
this.players.forEach(player => player.play());
|
||||
}
|
||||
|
||||
pause(): void { this._players.forEach(player => player.pause()); }
|
||||
pause(): void { this.players.forEach(player => player.pause()); }
|
||||
|
||||
restart(): void { this._players.forEach(player => player.restart()); }
|
||||
restart(): void { this.players.forEach(player => player.restart()); }
|
||||
|
||||
finish(): void {
|
||||
this._onFinish();
|
||||
this._players.forEach(player => player.finish());
|
||||
this.players.forEach(player => player.finish());
|
||||
}
|
||||
|
||||
destroy(): void { this._onDestroy(); }
|
||||
|
@ -101,14 +103,14 @@ export class AnimationGroupPlayer implements AnimationPlayer {
|
|||
if (!this._destroyed) {
|
||||
this._destroyed = true;
|
||||
this._onFinish();
|
||||
this._players.forEach(player => player.destroy());
|
||||
this.players.forEach(player => player.destroy());
|
||||
this._onDestroyFns.forEach(fn => fn());
|
||||
this._onDestroyFns = [];
|
||||
}
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this._players.forEach(player => player.reset());
|
||||
this.players.forEach(player => player.reset());
|
||||
this._destroyed = false;
|
||||
this._finished = false;
|
||||
this._started = false;
|
||||
|
@ -116,7 +118,7 @@ export class AnimationGroupPlayer implements AnimationPlayer {
|
|||
|
||||
setPosition(p: number): void {
|
||||
const timeAtPosition = p * this.totalTime;
|
||||
this._players.forEach(player => {
|
||||
this.players.forEach(player => {
|
||||
const position = player.totalTime ? Math.min(1, timeAtPosition / player.totalTime) : 1;
|
||||
player.setPosition(position);
|
||||
});
|
||||
|
@ -124,15 +126,13 @@ export class AnimationGroupPlayer implements AnimationPlayer {
|
|||
|
||||
getPosition(): number {
|
||||
let min = 0;
|
||||
this._players.forEach(player => {
|
||||
this.players.forEach(player => {
|
||||
const p = player.getPosition();
|
||||
min = Math.min(p, min);
|
||||
});
|
||||
return min;
|
||||
}
|
||||
|
||||
get players(): AnimationPlayer[] { return this._players; }
|
||||
|
||||
beforeDestroy(): void {
|
||||
this.players.forEach(player => {
|
||||
if (player.beforeDestroy) {
|
||||
|
|
|
@ -18,13 +18,16 @@
|
|||
* @stable
|
||||
*/
|
||||
export class Version {
|
||||
constructor(public full: string) {}
|
||||
public readonly major: string;
|
||||
public readonly minor: string;
|
||||
public readonly patch: string;
|
||||
|
||||
get major(): string { return this.full.split('.')[0]; }
|
||||
|
||||
get minor(): string { return this.full.split('.')[1]; }
|
||||
|
||||
get patch(): string { return this.full.split('.').slice(2).join('.'); }
|
||||
constructor(public full: string) {
|
||||
const splits = full.split('.');
|
||||
this.major = splits[0];
|
||||
this.minor = splits[1];
|
||||
this.patch = splits.slice(2).join('.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -169,12 +169,11 @@ function invertMap(obj: {[name: string]: string}): {[name: string]: string} {
|
|||
* Wrap a symbol and change its kind to component.
|
||||
*/
|
||||
class OverrideKindSymbol implements Symbol {
|
||||
constructor(private sym: Symbol, private kindOverride: string) {}
|
||||
public readonly kind: string;
|
||||
constructor(private sym: Symbol, kindOverride: string) { this.kind = kindOverride; }
|
||||
|
||||
get name(): string { return this.sym.name; }
|
||||
|
||||
get kind(): string { return this.kindOverride; }
|
||||
|
||||
get language(): string { return this.sym.language; }
|
||||
|
||||
get type(): Symbol|undefined { return this.sym.type; }
|
||||
|
|
|
@ -32,8 +32,9 @@ const baseHtmlParser = new InjectionToken('HtmlParser');
|
|||
|
||||
export class CompilerImpl implements Compiler {
|
||||
private _delegate: JitCompiler;
|
||||
public readonly injector: Injector;
|
||||
constructor(
|
||||
private _injector: Injector, private _metadataResolver: CompileMetadataResolver,
|
||||
injector: Injector, private _metadataResolver: CompileMetadataResolver,
|
||||
templateParser: TemplateParser, styleCompiler: StyleCompiler, viewCompiler: ViewCompiler,
|
||||
ngModuleCompiler: NgModuleCompiler, summaryResolver: SummaryResolver<Type<any>>,
|
||||
compileReflector: CompileReflector, compilerConfig: CompilerConfig, console: Console) {
|
||||
|
@ -41,10 +42,9 @@ export class CompilerImpl implements Compiler {
|
|||
_metadataResolver, templateParser, styleCompiler, viewCompiler, ngModuleCompiler,
|
||||
summaryResolver, compileReflector, compilerConfig, console,
|
||||
this.getExtraNgModuleProviders.bind(this));
|
||||
this.injector = injector;
|
||||
}
|
||||
|
||||
get injector(): Injector { return this._injector; }
|
||||
|
||||
private getExtraNgModuleProviders() {
|
||||
return [this._metadataResolver.getProviderMetadata(
|
||||
new ProviderMeta(Compiler, {useValue: this}))];
|
||||
|
|
|
@ -23,7 +23,7 @@ import {supportsState} from './history';
|
|||
*/
|
||||
@Injectable()
|
||||
export class BrowserPlatformLocation extends PlatformLocation {
|
||||
private _location: Location;
|
||||
public readonly location: Location;
|
||||
private _history: History;
|
||||
|
||||
constructor(@Inject(DOCUMENT) private _doc: any) {
|
||||
|
@ -34,12 +34,10 @@ export class BrowserPlatformLocation extends PlatformLocation {
|
|||
// This is moved to its own method so that `MockPlatformLocationStrategy` can overwrite it
|
||||
/** @internal */
|
||||
_init() {
|
||||
this._location = getDOM().getLocation();
|
||||
(this as{location: Location}).location = getDOM().getLocation();
|
||||
this._history = getDOM().getHistory();
|
||||
}
|
||||
|
||||
get location(): Location { return this._location; }
|
||||
|
||||
getBaseHrefFromDOM(): string { return getDOM().getBaseHref(this._doc) !; }
|
||||
|
||||
onPopState(fn: LocationChangeListener): void {
|
||||
|
@ -50,16 +48,16 @@ export class BrowserPlatformLocation extends PlatformLocation {
|
|||
getDOM().getGlobalEventTarget(this._doc, 'window').addEventListener('hashchange', fn, false);
|
||||
}
|
||||
|
||||
get pathname(): string { return this._location.pathname; }
|
||||
get search(): string { return this._location.search; }
|
||||
get hash(): string { return this._location.hash; }
|
||||
set pathname(newPath: string) { this._location.pathname = newPath; }
|
||||
get pathname(): string { return this.location.pathname; }
|
||||
get search(): string { return this.location.search; }
|
||||
get hash(): string { return this.location.hash; }
|
||||
set pathname(newPath: string) { this.location.pathname = newPath; }
|
||||
|
||||
pushState(state: any, title: string, url: string): void {
|
||||
if (supportsState()) {
|
||||
this._history.pushState(state, title, url);
|
||||
} else {
|
||||
this._location.hash = url;
|
||||
this.location.hash = url;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +65,7 @@ export class BrowserPlatformLocation extends PlatformLocation {
|
|||
if (supportsState()) {
|
||||
this._history.replaceState(state, title, url);
|
||||
} else {
|
||||
this._location.hash = url;
|
||||
this.location.hash = url;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,9 +29,9 @@ function parseUrl(urlStr: string): {pathname: string, search: string, hash: stri
|
|||
*/
|
||||
@Injectable()
|
||||
export class ServerPlatformLocation implements PlatformLocation {
|
||||
private _path: string = '/';
|
||||
private _search: string = '';
|
||||
private _hash: string = '';
|
||||
public readonly pathname: string = '/';
|
||||
public readonly search: string = '';
|
||||
public readonly hash: string = '';
|
||||
private _hashUpdate = new Subject<LocationChangeEvent>();
|
||||
|
||||
constructor(
|
||||
|
@ -39,9 +39,9 @@ export class ServerPlatformLocation implements PlatformLocation {
|
|||
const config = _config as PlatformConfig | null;
|
||||
if (!!config && !!config.url) {
|
||||
const parsedUrl = parseUrl(config.url);
|
||||
this._path = parsedUrl.pathname;
|
||||
this._search = parsedUrl.search;
|
||||
this._hash = parsedUrl.hash;
|
||||
this.pathname = parsedUrl.pathname;
|
||||
this.search = parsedUrl.search;
|
||||
this.hash = parsedUrl.hash;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,18 +54,14 @@ export class ServerPlatformLocation implements PlatformLocation {
|
|||
|
||||
onHashChange(fn: LocationChangeListener): void { this._hashUpdate.subscribe(fn); }
|
||||
|
||||
get pathname(): string { return this._path; }
|
||||
get search(): string { return this._search; }
|
||||
get hash(): string { return this._hash; }
|
||||
|
||||
get url(): string { return `${this.pathname}${this.search}${this.hash}`; }
|
||||
|
||||
private setHash(value: string, oldUrl: string) {
|
||||
if (this._hash === value) {
|
||||
if (this.hash === value) {
|
||||
// Don't fire events if the hash has not changed.
|
||||
return;
|
||||
}
|
||||
this._hash = value;
|
||||
(this as{hash: string}).hash = value;
|
||||
const newUrl = this.url;
|
||||
scheduleMicroTask(
|
||||
() => this._hashUpdate.next({ type: 'hashchange', oldUrl, newUrl } as LocationChangeEvent));
|
||||
|
@ -74,8 +70,8 @@ export class ServerPlatformLocation implements PlatformLocation {
|
|||
replaceState(state: any, title: string, newUrl: string): void {
|
||||
const oldUrl = this.url;
|
||||
const parsedUrl = parseUrl(newUrl);
|
||||
this._path = parsedUrl.pathname;
|
||||
this._search = parsedUrl.search;
|
||||
(this as{pathname: string}).pathname = parsedUrl.pathname;
|
||||
(this as{search: string}).search = parsedUrl.search;
|
||||
this.setHash(parsedUrl.hash, oldUrl);
|
||||
}
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ export class RouterLinkActive implements OnChanges,
|
|||
|
||||
private classes: string[] = [];
|
||||
private subscription: Subscription;
|
||||
private active: boolean = false;
|
||||
public readonly isActive: boolean = false;
|
||||
|
||||
@Input() routerLinkActiveOptions: {exact: boolean} = {exact: false};
|
||||
|
||||
|
@ -100,7 +100,6 @@ export class RouterLinkActive implements OnChanges,
|
|||
});
|
||||
}
|
||||
|
||||
get isActive(): boolean { return this.active; }
|
||||
|
||||
ngAfterContentInit(): void {
|
||||
this.links.changes.subscribe(_ => this.update());
|
||||
|
@ -122,7 +121,7 @@ export class RouterLinkActive implements OnChanges,
|
|||
const hasActiveLinks = this.hasActiveLinks();
|
||||
|
||||
// react only when status has changed to prevent unnecessary dom updates
|
||||
if (this.active !== hasActiveLinks) {
|
||||
if (this.isActive !== hasActiveLinks) {
|
||||
this.classes.forEach((c) => {
|
||||
if (hasActiveLinks) {
|
||||
this.renderer.addClass(this.element.nativeElement, c);
|
||||
|
@ -130,7 +129,9 @@ export class RouterLinkActive implements OnChanges,
|
|||
this.renderer.removeClass(this.element.nativeElement, c);
|
||||
}
|
||||
});
|
||||
Promise.resolve(hasActiveLinks).then(active => this.active = active);
|
||||
Promise.resolve(hasActiveLinks).then(active => (this as{
|
||||
isActive: boolean
|
||||
}).isActive = active);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ export class RouterOutlet implements OnDestroy, OnInit {
|
|||
}
|
||||
this._activatedRoute = activatedRoute;
|
||||
const snapshot = activatedRoute._futureSnapshot;
|
||||
const component = <any>snapshot._routeConfig !.component;
|
||||
const component = <any>snapshot.routeConfig !.component;
|
||||
resolver = resolver || this.resolver;
|
||||
const factory = resolver.resolveComponentFactory(component);
|
||||
const childContexts = this.parentContexts.getOrCreateContext(this.name).children;
|
||||
|
|
|
@ -108,9 +108,9 @@ export class PreActivation {
|
|||
const context = parentContexts ? parentContexts.getContext(futureNode.value.outlet) : null;
|
||||
|
||||
// reusing the node
|
||||
if (curr && future._routeConfig === curr._routeConfig) {
|
||||
if (curr && future.routeConfig === curr.routeConfig) {
|
||||
const shouldRunGuardsAndResolvers = this.shouldRunGuardsAndResolvers(
|
||||
curr, future, future._routeConfig !.runGuardsAndResolvers);
|
||||
curr, future, future.routeConfig !.runGuardsAndResolvers);
|
||||
if (shouldRunGuardsAndResolvers) {
|
||||
this.canActivateChecks.push(new CanActivate(futurePath));
|
||||
} else {
|
||||
|
@ -241,7 +241,7 @@ export class PreActivation {
|
|||
}
|
||||
|
||||
private runCanActivate(future: ActivatedRouteSnapshot): Observable<boolean> {
|
||||
const canActivate = future._routeConfig ? future._routeConfig.canActivate : null;
|
||||
const canActivate = future.routeConfig ? future.routeConfig.canActivate : null;
|
||||
if (!canActivate || canActivate.length === 0) return of (true);
|
||||
const obs = map.call(from(canActivate), (c: any) => {
|
||||
const guard = this.getToken(c, future);
|
||||
|
@ -281,14 +281,14 @@ export class PreActivation {
|
|||
|
||||
private extractCanActivateChild(p: ActivatedRouteSnapshot):
|
||||
{node: ActivatedRouteSnapshot, guards: any[]}|null {
|
||||
const canActivateChild = p._routeConfig ? p._routeConfig.canActivateChild : null;
|
||||
const canActivateChild = p.routeConfig ? p.routeConfig.canActivateChild : null;
|
||||
if (!canActivateChild || canActivateChild.length === 0) return null;
|
||||
return {node: p, guards: canActivateChild};
|
||||
}
|
||||
|
||||
private runCanDeactivate(component: Object|null, curr: ActivatedRouteSnapshot):
|
||||
Observable<boolean> {
|
||||
const canDeactivate = curr && curr._routeConfig ? curr._routeConfig.canDeactivate : null;
|
||||
const canDeactivate = curr && curr.routeConfig ? curr.routeConfig.canDeactivate : null;
|
||||
if (!canDeactivate || canDeactivate.length === 0) return of (true);
|
||||
const canDeactivate$ = mergeMap.call(from(canDeactivate), (c: any) => {
|
||||
const guard = this.getToken(c, curr);
|
||||
|
@ -351,7 +351,7 @@ function closestLoadedConfig(snapshot: ActivatedRouteSnapshot): LoadedRouterConf
|
|||
if (!snapshot) return null;
|
||||
|
||||
for (let s = snapshot.parent; s; s = s.parent) {
|
||||
const route = s._routeConfig;
|
||||
const route = s.routeConfig;
|
||||
if (route && route._loadedConfig) return route._loadedConfig;
|
||||
}
|
||||
|
||||
|
|
|
@ -200,16 +200,16 @@ function defaultRouterHook(snapshot: RouterStateSnapshot): Observable<void> {
|
|||
export class Router {
|
||||
private currentUrlTree: UrlTree;
|
||||
private rawUrlTree: UrlTree;
|
||||
|
||||
private navigations = new BehaviorSubject<NavigationParams>(null !);
|
||||
private routerEvents = new Subject<Event>();
|
||||
|
||||
private currentRouterState: RouterState;
|
||||
private locationSubscription: Subscription;
|
||||
private navigationId: number = 0;
|
||||
private configLoader: RouterConfigLoader;
|
||||
private ngModule: NgModuleRef<any>;
|
||||
|
||||
public readonly events: Observable<Event> = new Subject<Event>();
|
||||
public readonly routerState: RouterState;
|
||||
|
||||
/**
|
||||
* Error handler that is invoked when a navigation errors.
|
||||
*
|
||||
|
@ -259,7 +259,7 @@ export class Router {
|
|||
this.rawUrlTree = this.currentUrlTree;
|
||||
|
||||
this.configLoader = new RouterConfigLoader(loader, compiler, onLoadStart, onLoadEnd);
|
||||
this.currentRouterState = createEmptyState(this.currentUrlTree, this.rootComponentType);
|
||||
this.routerState = createEmptyState(this.currentUrlTree, this.rootComponentType);
|
||||
this.processNavigations();
|
||||
}
|
||||
|
||||
|
@ -271,7 +271,7 @@ export class Router {
|
|||
this.rootComponentType = rootComponentType;
|
||||
// TODO: vsavkin router 4.0 should make the root component set to null
|
||||
// this will simplify the lifecycle of the router.
|
||||
this.currentRouterState.root.component = this.rootComponentType;
|
||||
this.routerState.root.component = this.rootComponentType;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -299,17 +299,11 @@ export class Router {
|
|||
}
|
||||
}
|
||||
|
||||
/** The current route state */
|
||||
get routerState(): RouterState { return this.currentRouterState; }
|
||||
|
||||
/** The current url */
|
||||
get url(): string { return this.serializeUrl(this.currentUrlTree); }
|
||||
|
||||
/** An observable of router events */
|
||||
get events(): Observable<Event> { return this.routerEvents; }
|
||||
|
||||
/** @internal */
|
||||
triggerEvent(e: Event): void { this.routerEvents.next(e); }
|
||||
triggerEvent(e: Event): void { (this.events as Subject<Event>).next(e); }
|
||||
|
||||
/**
|
||||
* Resets the configuration used for navigation and generating links.
|
||||
|
@ -552,7 +546,7 @@ export class Router {
|
|||
const urlTransition = !this.navigated || url.toString() !== this.currentUrlTree.toString();
|
||||
|
||||
if (urlTransition && this.urlHandlingStrategy.shouldProcessUrl(rawUrl)) {
|
||||
this.routerEvents.next(new NavigationStart(id, this.serializeUrl(url)));
|
||||
(this.events as Subject<Event>).next(new NavigationStart(id, this.serializeUrl(url)));
|
||||
Promise.resolve()
|
||||
.then(
|
||||
(_) => this.runNavigate(
|
||||
|
@ -564,7 +558,7 @@ export class Router {
|
|||
} else if (
|
||||
urlTransition && this.rawUrlTree &&
|
||||
this.urlHandlingStrategy.shouldProcessUrl(this.rawUrlTree)) {
|
||||
this.routerEvents.next(new NavigationStart(id, this.serializeUrl(url)));
|
||||
(this.events as Subject<Event>).next(new NavigationStart(id, this.serializeUrl(url)));
|
||||
Promise.resolve()
|
||||
.then(
|
||||
(_) => this.runNavigate(
|
||||
|
@ -583,9 +577,10 @@ export class Router {
|
|||
id: number, precreatedState: RouterStateSnapshot|null): Promise<boolean> {
|
||||
if (id !== this.navigationId) {
|
||||
this.location.go(this.urlSerializer.serialize(this.currentUrlTree));
|
||||
this.routerEvents.next(new NavigationCancel(
|
||||
id, this.serializeUrl(url),
|
||||
`Navigation ID ${id} is not equal to the current navigation id ${this.navigationId}`));
|
||||
(this.events as Subject<Event>)
|
||||
.next(new NavigationCancel(
|
||||
id, this.serializeUrl(url),
|
||||
`Navigation ID ${id} is not equal to the current navigation id ${this.navigationId}`));
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
|
@ -604,8 +599,9 @@ export class Router {
|
|||
this.rootComponentType, this.config, appliedUrl, this.serializeUrl(appliedUrl)),
|
||||
(snapshot: any) => {
|
||||
|
||||
this.routerEvents.next(new RoutesRecognized(
|
||||
id, this.serializeUrl(url), this.serializeUrl(appliedUrl), snapshot));
|
||||
(this.events as Subject<Event>)
|
||||
.next(new RoutesRecognized(
|
||||
id, this.serializeUrl(url), this.serializeUrl(appliedUrl), snapshot));
|
||||
|
||||
return {appliedUrl, snapshot};
|
||||
});
|
||||
|
@ -627,7 +623,7 @@ export class Router {
|
|||
({appliedUrl, snapshot}: {appliedUrl: string, snapshot: RouterStateSnapshot}) => {
|
||||
const moduleInjector = this.ngModule.injector;
|
||||
preActivation = new PreActivation(
|
||||
snapshot, this.currentRouterState.snapshot, moduleInjector,
|
||||
snapshot, this.routerState.snapshot, moduleInjector,
|
||||
(evt: Event) => this.triggerEvent(evt));
|
||||
preActivation.initalize(this.rootContexts);
|
||||
return {appliedUrl, snapshot};
|
||||
|
@ -676,8 +672,7 @@ export class Router {
|
|||
const routerState$ =
|
||||
map.call(preactivationDone$, ({appliedUrl, snapshot, shouldActivate}: any) => {
|
||||
if (shouldActivate) {
|
||||
const state =
|
||||
createRouterState(this.routeReuseStrategy, snapshot, this.currentRouterState);
|
||||
const state = createRouterState(this.routeReuseStrategy, snapshot, this.routerState);
|
||||
return {appliedUrl, state, shouldActivate};
|
||||
} else {
|
||||
return {appliedUrl, state: null, shouldActivate};
|
||||
|
@ -688,7 +683,7 @@ export class Router {
|
|||
// applied the new router state
|
||||
// this operation has side effects
|
||||
let navigationIsSuccessful: boolean;
|
||||
const storedState = this.currentRouterState;
|
||||
const storedState = this.routerState;
|
||||
const storedUrl = this.currentUrlTree;
|
||||
|
||||
routerState$
|
||||
|
@ -701,7 +696,7 @@ export class Router {
|
|||
this.currentUrlTree = appliedUrl;
|
||||
this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl);
|
||||
|
||||
this.currentRouterState = state;
|
||||
(this as{routerState: RouterState}).routerState = state;
|
||||
|
||||
if (!shouldPreventPushState) {
|
||||
const path = this.urlSerializer.serialize(this.rawUrlTree);
|
||||
|
@ -722,12 +717,14 @@ export class Router {
|
|||
() => {
|
||||
if (navigationIsSuccessful) {
|
||||
this.navigated = true;
|
||||
this.routerEvents.next(new NavigationEnd(
|
||||
id, this.serializeUrl(url), this.serializeUrl(this.currentUrlTree)));
|
||||
(this.events as Subject<Event>)
|
||||
.next(new NavigationEnd(
|
||||
id, this.serializeUrl(url), this.serializeUrl(this.currentUrlTree)));
|
||||
resolvePromise(true);
|
||||
} else {
|
||||
this.resetUrlToCurrentUrlTree();
|
||||
this.routerEvents.next(new NavigationCancel(id, this.serializeUrl(url), ''));
|
||||
(this.events as Subject<Event>)
|
||||
.next(new NavigationCancel(id, this.serializeUrl(url), ''));
|
||||
resolvePromise(false);
|
||||
}
|
||||
},
|
||||
|
@ -735,11 +732,12 @@ export class Router {
|
|||
if (isNavigationCancelingError(e)) {
|
||||
this.resetUrlToCurrentUrlTree();
|
||||
this.navigated = true;
|
||||
this.routerEvents.next(
|
||||
new NavigationCancel(id, this.serializeUrl(url), e.message));
|
||||
(this.events as Subject<Event>)
|
||||
.next(new NavigationCancel(id, this.serializeUrl(url), e.message));
|
||||
resolvePromise(false);
|
||||
} else {
|
||||
this.routerEvents.next(new NavigationError(id, this.serializeUrl(url), e));
|
||||
(this.events as Subject<Event>)
|
||||
.next(new NavigationError(id, this.serializeUrl(url), e));
|
||||
try {
|
||||
resolvePromise(this.errorHandler(e));
|
||||
} catch (ee) {
|
||||
|
@ -747,7 +745,7 @@ export class Router {
|
|||
}
|
||||
}
|
||||
|
||||
this.currentRouterState = storedState;
|
||||
(this as{routerState: RouterState}).routerState = storedState;
|
||||
this.currentUrlTree = storedUrl;
|
||||
this.rawUrlTree = this.urlHandlingStrategy.merge(this.currentUrlTree, rawUrl);
|
||||
this.location.replaceState(this.serializeUrl(this.rawUrlTree));
|
||||
|
@ -936,7 +934,7 @@ function advanceActivatedRouteNodeAndItsChildren(node: TreeNode<ActivatedRoute>)
|
|||
|
||||
function parentLoadedConfig(snapshot: ActivatedRouteSnapshot): LoadedRouterConfig|null {
|
||||
for (let s = snapshot.parent; s; s = s.parent) {
|
||||
const route = s._routeConfig;
|
||||
const route = s.routeConfig;
|
||||
if (route && route._loadedConfig) return route._loadedConfig;
|
||||
if (route && route.component) return null;
|
||||
}
|
||||
|
|
|
@ -233,8 +233,8 @@ export function inheritedParamsDataResolve(route: ActivatedRouteSnapshot): Inher
|
|||
* @stable
|
||||
*/
|
||||
export class ActivatedRouteSnapshot {
|
||||
/** @internal **/
|
||||
_routeConfig: Route|null;
|
||||
/** The configuration used to match this route **/
|
||||
public readonly routeConfig: Route|null;
|
||||
/** @internal **/
|
||||
_urlSegment: UrlSegmentGroup;
|
||||
/** @internal */
|
||||
|
@ -267,15 +267,12 @@ export class ActivatedRouteSnapshot {
|
|||
/** The component of the route */
|
||||
public component: Type<any>|string|null, routeConfig: Route|null, urlSegment: UrlSegmentGroup,
|
||||
lastPathIndex: number, resolve: ResolveData) {
|
||||
this._routeConfig = routeConfig;
|
||||
this.routeConfig = routeConfig;
|
||||
this._urlSegment = urlSegment;
|
||||
this._lastPathIndex = lastPathIndex;
|
||||
this._resolve = resolve;
|
||||
}
|
||||
|
||||
/** The configuration used to match this route */
|
||||
get routeConfig(): Route|null { return this._routeConfig; }
|
||||
|
||||
/** The root of the router state */
|
||||
get root(): ActivatedRouteSnapshot { return this._routerState.root; }
|
||||
|
||||
|
@ -307,7 +304,7 @@ export class ActivatedRouteSnapshot {
|
|||
|
||||
toString(): string {
|
||||
const url = this.url.map(segment => segment.toString()).join('/');
|
||||
const matched = this._routeConfig ? this._routeConfig.path : '';
|
||||
const matched = this.routeConfig ? this.routeConfig.path : '';
|
||||
return `Route(url:'${url}', path:'${matched}')`;
|
||||
}
|
||||
}
|
||||
|
@ -400,4 +397,4 @@ export function equalParamsAndUrlSegments(
|
|||
|
||||
return equalUrlParams && !parentsMismatch &&
|
||||
(!a.parent || equalParamsAndUrlSegments(a.parent, b.parent !));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue