Skip to content

Commit

Permalink
fix: asynchronously destroy items evicted on clearHistory navigation (#…
Browse files Browse the repository at this point in the history
…847)

fixes #829
  • Loading branch information
buuhuu authored and sis0k0 committed Jul 12, 2017
1 parent 7b6bf4f commit 448412a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions nativescript-angular/router/page-router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
private refCache: RefCache = new RefCache();
private isInitialPage: boolean = true;
private detachedLoaderFactory: ComponentFactory<DetachedLoader>;
private itemsToDestroy: CacheItem[] = [];

private currentActivatedComp: ComponentRef<any>;
private currentActivatedRoute: ActivatedRoute;
Expand Down Expand Up @@ -132,7 +133,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) {
Expand Down Expand Up @@ -242,7 +248,10 @@ export class PageRouterOutlet { // tslint:disable-line:directive-class-suffix
// Add it to the new page
page.content = componentView;

page.on("navigatedFrom", (<any>global).Zone.current.wrap((args: NavigatedData) => {
page.on(Page.navigatedToEvent, () => setTimeout(() => {
this.destroyQueuedCacheItems();
}));
page.on(Page.navigatedFromEvent, (<any>global).Zone.current.wrap((args: NavigatedData) => {
if (args.isBackNavigation) {
this.locationStrategy._beginBackPageNavigation();
this.locationStrategy.back();
Expand Down

0 comments on commit 448412a

Please sign in to comment.