From 4ab6c2fc18d56fad97fe91b5ac8b70cdde35e1a4 Mon Sep 17 00:00:00 2001 From: Veselina Radeva Date: Thu, 29 Mar 2018 17:37:00 +0300 Subject: [PATCH 1/4] docs: update issue template --- .../router/ns-location-strategy.ts | 38 ++++++++++--------- .../router/page-router-outlet.ts | 19 +++++++--- nativescript-angular/trace.ts | 4 ++ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/nativescript-angular/router/ns-location-strategy.ts b/nativescript-angular/router/ns-location-strategy.ts index 7cf31e270..9db95c617 100644 --- a/nativescript-angular/router/ns-location-strategy.ts +++ b/nativescript-angular/router/ns-location-strategy.ts @@ -1,7 +1,7 @@ import { Injectable } from "@angular/core"; import { LocationStrategy } from "@angular/common"; import { DefaultUrlSerializer, UrlSegmentGroup, UrlTree } from "@angular/router"; -import { routerLog } from "../trace"; +import { routerLog, routerError } from "../trace"; import { NavigationTransition, Frame } from "tns-core-modules/ui/frame"; import { isPresent } from "../lang-facade"; import { FrameService } from "../platform-providers"; @@ -286,10 +286,11 @@ export class NSLocationStrategy extends LocationStrategy { // Methods for syncing with page navigation in PageRouterOutlet public _beginBackPageNavigation(name: string, frame: Frame) { - routerLog("NSLocationStrategy.startGoBack()"); if (this._isPageNavigationBack) { - throw new Error("Calling startGoBack while going back."); + routerError("Attempted to call startGoBack while going back."); + return; } + routerLog("NSLocationStrategy.startGoBack()"); this._isPageNavigationBack = true; let { cachedFrame } = this.frameService.findFrame(frame); @@ -302,10 +303,11 @@ export class NSLocationStrategy extends LocationStrategy { } public _finishBackPageNavigation() { - routerLog("NSLocationStrategy.finishBackPageNavigation()"); if (!this._isPageNavigationBack) { - throw new Error("Calling endGoBack while not going back."); + routerError("Attempted to call endGoBack while not going back."); + return; } + routerLog("NSLocationStrategy.finishBackPageNavigation()"); this._isPageNavigationBack = false; } @@ -314,33 +316,35 @@ export class NSLocationStrategy extends LocationStrategy { } public _beginModalNavigation(frame: Frame): void { - routerLog("NSLocationStrategy._beginModalNavigation()"); + routerLog("NSLocationStrategy._beginModalNavigation()"); - let { cachedFrameRootOutlet } = this.frameService.findFrame(frame); + let { cachedFrameRootOutlet } = this.frameService.findFrame(frame); - const lastState = this.peekState(cachedFrameRootOutlet || this.currentOutlet); + const lastState = this.peekState(cachedFrameRootOutlet || this.currentOutlet); - if (lastState) { - lastState.isModalNavigation = true; - } + if (lastState) { + lastState.isModalNavigation = true; + } - this._isModalNavigation = true; - } + this._isModalNavigation = true; + } public _beginCloseModalNavigation(): void { - routerLog("NSLocationStrategy.startCloseModal()"); if (this._isModalClosing) { - throw new Error("Calling startCloseModal while closing modal."); + routerError("Attempted to call startCloseModal while closing modal."); + return; } + routerLog("NSLocationStrategy.startCloseModal()"); this._isModalClosing = true; } public _finishCloseModalNavigation() { - routerLog("NSLocationStrategy.finishCloseModalNavigation()"); if (!this._isModalClosing) { - throw new Error("Calling startCloseModal while not closing modal."); + routerError("Attempted to call startCloseModal while not closing modal."); + return; } + routerLog("NSLocationStrategy.finishCloseModalNavigation()"); this._isModalNavigation = false; this._isModalClosing = false; } diff --git a/nativescript-angular/router/page-router-outlet.ts b/nativescript-angular/router/page-router-outlet.ts index 565414386..bfd1c25d1 100644 --- a/nativescript-angular/router/page-router-outlet.ts +++ b/nativescript-angular/router/page-router-outlet.ts @@ -102,6 +102,8 @@ function routeToString(activatedRoute: ActivatedRoute | ActivatedRouteSnapshot): return activatedRoute.pathFromRoot.join("->"); } +const routeTransitionWarning = "This could be due to route transition timing and could be ignored."; + @Directive({ selector: "page-router-outlet" }) // tslint:disable-line:directive-selector export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:directive-class-suffix private activated: ComponentRef | null = null; @@ -126,14 +128,16 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire get component(): Object { if (!this.activated) { - throw new Error("Outlet is not activated"); + log("Outlet is not activated"); + return; } return this.activated.instance; } get activatedRoute(): ActivatedRoute { if (!this.activated) { - throw new Error("Outlet is not activated"); + log("Outlet is not activated"); + return; } return this._activatedRoute; @@ -173,8 +177,9 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire deactivate(): void { if (!this.locationStrategy._isPageNavigatingBack()) { - throw new Error("Currently not in page back navigation" + - " - component should be detached instead of deactivated."); + log("Currently not in page back navigation" + + " - component should be detached instead of deactivated." + routeTransitionWarning); + return; } log("PageRouterOutlet.deactivate() while going back - should destroy"); @@ -197,7 +202,8 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire */ detach(): ComponentRef { if (!this.isActivated) { - throw new Error("Outlet is not activated"); + log("Outlet is not activated"); + return; } log("PageRouterOutlet.detach() - " + routeToString(this._activatedRoute)); @@ -232,7 +238,8 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire resolver: ComponentFactoryResolver | null): void { if (this.locationStrategy._isPageNavigatingBack()) { - throw new Error("Currently in page back navigation - component should be reattached instead of activated."); + log("Currently in page back navigation - component should be reattached instead of activated. " + routeTransitionWarning); + this.locationStrategy._finishBackPageNavigation(); } log("PageRouterOutlet.activateWith() - " + routeToString(activatedRoute)); diff --git a/nativescript-angular/trace.ts b/nativescript-angular/trace.ts index 486943791..3758696b2 100644 --- a/nativescript-angular/trace.ts +++ b/nativescript-angular/trace.ts @@ -28,6 +28,10 @@ export function routerLog(message: string): void { write(message, routerTraceCategory); } +export function routerError(message: string): void { + write(message, routerTraceCategory, messageType.error); +} + export function routeReuseStrategyLog(message: string): void { write(message, routeReuseStrategyTraceCategory); } From 31ad9908797fbac15f1eda95d17c1b63eaa83a3d Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Fri, 27 Jul 2018 08:05:43 +0300 Subject: [PATCH 2/4] chore: fix tslint --- nativescript-angular/router/page-router-outlet.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nativescript-angular/router/page-router-outlet.ts b/nativescript-angular/router/page-router-outlet.ts index bfd1c25d1..d0ab0e1de 100644 --- a/nativescript-angular/router/page-router-outlet.ts +++ b/nativescript-angular/router/page-router-outlet.ts @@ -238,7 +238,8 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire resolver: ComponentFactoryResolver | null): void { if (this.locationStrategy._isPageNavigatingBack()) { - log("Currently in page back navigation - component should be reattached instead of activated. " + routeTransitionWarning); + log("Currently in page back navigation - component should be reattached instead of activated. " + + routeTransitionWarning); this.locationStrategy._finishBackPageNavigation(); } From 971d05c0973b5c971580e13770f8655977252fb3 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Fri, 27 Jul 2018 08:08:43 +0300 Subject: [PATCH 3/4] chore: fix tslint - again --- nativescript-angular/router/page-router-outlet.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nativescript-angular/router/page-router-outlet.ts b/nativescript-angular/router/page-router-outlet.ts index d0ab0e1de..0114cf872 100644 --- a/nativescript-angular/router/page-router-outlet.ts +++ b/nativescript-angular/router/page-router-outlet.ts @@ -238,7 +238,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire resolver: ComponentFactoryResolver | null): void { if (this.locationStrategy._isPageNavigatingBack()) { - log("Currently in page back navigation - component should be reattached instead of activated. " + + log("Currently in page back navigation - component should be reattached instead of activated. " + routeTransitionWarning); this.locationStrategy._finishBackPageNavigation(); } From 9548fd91087f18729aa7454a74c9aafca5081e3b Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Fri, 27 Jul 2018 13:41:57 +0300 Subject: [PATCH 4/4] chore: remove routeTransitionWarning --- nativescript-angular/router/page-router-outlet.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/nativescript-angular/router/page-router-outlet.ts b/nativescript-angular/router/page-router-outlet.ts index 0114cf872..d9dc46776 100644 --- a/nativescript-angular/router/page-router-outlet.ts +++ b/nativescript-angular/router/page-router-outlet.ts @@ -102,8 +102,6 @@ function routeToString(activatedRoute: ActivatedRoute | ActivatedRouteSnapshot): return activatedRoute.pathFromRoot.join("->"); } -const routeTransitionWarning = "This could be due to route transition timing and could be ignored."; - @Directive({ selector: "page-router-outlet" }) // tslint:disable-line:directive-selector export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:directive-class-suffix private activated: ComponentRef | null = null; @@ -177,8 +175,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire deactivate(): void { if (!this.locationStrategy._isPageNavigatingBack()) { - log("Currently not in page back navigation" + - " - component should be detached instead of deactivated." + routeTransitionWarning); + log("Currently not in page back navigation - component should be detached instead of deactivated."); return; } @@ -238,8 +235,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire resolver: ComponentFactoryResolver | null): void { if (this.locationStrategy._isPageNavigatingBack()) { - log("Currently in page back navigation - component should be reattached instead of activated. " + - routeTransitionWarning); + log("Currently in page back navigation - component should be reattached instead of activated."); this.locationStrategy._finishBackPageNavigation(); }