From 1a1e36c44cb29cdf00fd602eb81e151ba491e087 Mon Sep 17 00:00:00 2001 From: "michael.bradford@liferay.com" Date: Fri, 27 May 2016 18:06:45 -0700 Subject: [PATCH 1/2] Wait until pending navigate is complete before removing screen --- src/app/App.js | 9 ++++++++- test/app/App.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/app/App.js b/src/app/App.js index 7c83d0b..bceff58 100644 --- a/src/app/App.js +++ b/src/app/App.js @@ -499,7 +499,14 @@ class App extends EventEmitter { handleNavigateError_(path, nextScreen, err) { console.log('Navigation error for [' + nextScreen + '] (' + err + ')'); if (!utils.isCurrentBrowserPath(path)) { - this.removeScreen(path); + if (this.pendingNavigate) { + this.pendingNavigate.thenAlways(function() { + this.removeScreen(path); + }, this); + } + else { + this.removeScreen(path); + } } } diff --git a/test/app/App.js b/test/app/App.js index 1330263..b6a53ec 100644 --- a/test/app/App.js +++ b/test/app/App.js @@ -1261,6 +1261,36 @@ describe('App', function() { .cancel(); }); + it('should wait for pendingNavigate before removing screen on double back navigation', (done) => { + class CacheScreen extends Screen { + constructor() { + super(); + this.cacheable = true; + } + } + + var app = new App(); + this.app = app; + app.addRoutes(new Route('/path1', CacheScreen)); + app.addRoutes(new Route('/path2', CacheScreen)); + app.addRoutes(new Route('/path3', CacheScreen)); + + app.navigate('/path1') + .then(() => app.navigate('/path2')) + .then(() => app.navigate('/path3')) + .then(() => { + app.on('endNavigate', function() { + assert.ok(app.screens['/path2']); + app.pendingNavigate.then(function() { + assert.ok(!app.screens['/path2']); + done(); + }); + }); + globals.window.history.back(); + globals.window.history.back(); + }); + }); + }); var canScrollIFrame_ = false; From fbb332134f2b6aa41a60d0bd334b31e035667cdc Mon Sep 17 00:00:00 2001 From: Bruno Basto Date: Mon, 6 Jun 2016 11:24:01 -0300 Subject: [PATCH 2/2] SF --- src/app/App.js | 4 +--- test/app/App.js | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/app/App.js b/src/app/App.js index bceff58..3a8f1b4 100644 --- a/src/app/App.js +++ b/src/app/App.js @@ -500,9 +500,7 @@ class App extends EventEmitter { console.log('Navigation error for [' + nextScreen + '] (' + err + ')'); if (!utils.isCurrentBrowserPath(path)) { if (this.pendingNavigate) { - this.pendingNavigate.thenAlways(function() { - this.removeScreen(path); - }, this); + this.pendingNavigate.thenAlways(() => this.removeScreen(path), this); } else { this.removeScreen(path); diff --git a/test/app/App.js b/test/app/App.js index b6a53ec..5a4cb20 100644 --- a/test/app/App.js +++ b/test/app/App.js @@ -1279,9 +1279,9 @@ describe('App', function() { .then(() => app.navigate('/path2')) .then(() => app.navigate('/path3')) .then(() => { - app.on('endNavigate', function() { + app.on('endNavigate', () => { assert.ok(app.screens['/path2']); - app.pendingNavigate.then(function() { + app.pendingNavigate.then(() => { assert.ok(!app.screens['/path2']); done(); });