From b9f07ae517adb64e9ecd32de4aa730c88d0a8353 Mon Sep 17 00:00:00 2001 From: Dirk Rudolph Date: Thu, 15 Jun 2017 09:40:05 +0200 Subject: [PATCH 1/3] - queue items evicted to be destroyed on clearRefCache instead of destroying them immediately. - finally destroy them on navigatedFrom event --- nativescript-angular/router/page-router-outlet.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nativescript-angular/router/page-router-outlet.ts b/nativescript-angular/router/page-router-outlet.ts index bc28fdd5b..c0abcfad5 100644 --- a/nativescript-angular/router/page-router-outlet.ts +++ b/nativescript-angular/router/page-router-outlet.ts @@ -63,6 +63,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix private refCache: RefCache = new RefCache(); private isInitialPage: boolean = true; private detachedLoaderFactory: ComponentFactory; + private itemsToDestroy: CacheItem[] = []; private currentActivatedComp: ComponentRef; private currentActivatedRoute: ActivatedRoute; @@ -131,7 +132,12 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix private clearRefCache() { while (this.refCache.length > 0) { - this.destroyCacheItem(this.refCache.pop()); + this.itemsToDestroy.push(this.refCache.pop()); + } + } + private destroyQueuedCacheItems() { + while(this.itemsToDestroy.length > 0) { + this.destroyCacheItem(this.itemsToDestroy.pop()); } } private destroyCacheItem(poppedItem: CacheItem) { @@ -244,6 +250,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix this.locationStrategy._beginBackPageNavigation(); this.locationStrategy.back(); } + setTimeout(() => this.destroyQueuedCacheItems()); })); const navOptions = this.locationStrategy._beginPageNavigation(); From 9e8cc7efef524d4ed2f580065368d987c22b4958 Mon Sep 17 00:00:00 2001 From: Dirk Rudolph Date: Thu, 15 Jun 2017 10:27:40 +0200 Subject: [PATCH 2/3] - fxied tslint errors --- 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 c0abcfad5..b00de8e79 100644 --- a/nativescript-angular/router/page-router-outlet.ts +++ b/nativescript-angular/router/page-router-outlet.ts @@ -136,7 +136,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix } } private destroyQueuedCacheItems() { - while(this.itemsToDestroy.length > 0) { + while (this.itemsToDestroy.length > 0) { this.destroyCacheItem(this.itemsToDestroy.pop()); } } From 781e4026bc5c8addd049cc10ae7d7069bccbc11d Mon Sep 17 00:00:00 2001 From: Dirk Rudolph Date: Sat, 1 Jul 2017 07:12:50 +0200 Subject: [PATCH 3/3] destroy the queued cache items on navigatedToEvent --- nativescript-angular/router/page-router-outlet.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nativescript-angular/router/page-router-outlet.ts b/nativescript-angular/router/page-router-outlet.ts index b00de8e79..7ec2245fc 100644 --- a/nativescript-angular/router/page-router-outlet.ts +++ b/nativescript-angular/router/page-router-outlet.ts @@ -245,12 +245,14 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix // Add it to the new page page.content = componentView; - page.on("navigatedFrom", (global).Zone.current.wrap((args: NavigatedData) => { + page.on(Page.navigatedToEvent, () => setTimeout(() => { + this.destroyQueuedCacheItems(); + })); + page.on(Page.navigatedFromEvent, (global).Zone.current.wrap((args: NavigatedData) => { if (args.isBackNavigation) { this.locationStrategy._beginBackPageNavigation(); this.locationStrategy.back(); } - setTimeout(() => this.destroyQueuedCacheItems()); })); const navOptions = this.locationStrategy._beginPageNavigation();