Skip to content

Commit

Permalink
fix(history): maintain nextViewOptions with resolves
Browse files Browse the repository at this point in the history
Closes #3027. Closes #3892
An updated fix for #3027
Launches the expiration timer only after successful state transition.
  • Loading branch information
vladipus authored and mhartington committed Jun 8, 2015
1 parent bcfe210 commit cef6708
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions js/angular/service/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
var DIRECTION_NONE = 'none';

var stateChangeCounter = 0;
var lastStateId, nextViewOptions, nextViewExpireTimer, forcedNav;
var lastStateId, nextViewOptions, deregisterStateChangeListener, nextViewExpireTimer, forcedNav;

var viewHistory = {
histories: { root: { historyId: 'root', parentHistoryId: null, stack: [], cursor: -1 } },
Expand Down Expand Up @@ -367,6 +367,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
hist.stack.push(viewHistory.views[viewId]);
}

deregisterStateChangeListener && deregisterStateChangeListener();
$timeout.cancel(nextViewExpireTimer);
if (nextViewOptions) {
if (nextViewOptions.disableAnimate) direction = DIRECTION_NONE;
Expand Down Expand Up @@ -682,6 +683,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
* ```
*/
nextViewOptions: function(opts) {
deregisterStateChangeListener && deregisterStateChangeListener();
if (arguments.length) {
$timeout.cancel(nextViewExpireTimer);
if (opts === null) {
Expand All @@ -690,9 +692,11 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $
nextViewOptions = nextViewOptions || {};
extend(nextViewOptions, opts);
if (nextViewOptions.expire) {
nextViewExpireTimer = $timeout(function() {
nextViewOptions = null;
}, nextViewOptions.expire);
deregisterStateChangeListener = $rootScope.$on('$stateChangeSuccess', function() {
nextViewExpireTimer = $timeout(function(){
nextViewOptions = null;
}, nextViewOptions.expire);
});
}
}
}
Expand Down

0 comments on commit cef6708

Please sign in to comment.