Skip to content

Commit

Permalink
fix(viewService): No error on clearHistory for empty history
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Aug 4, 2014
1 parent 5b99fd6 commit 64641b1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
30 changes: 17 additions & 13 deletions js/angular/service/viewService.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,21 +550,23 @@ function($rootScope, $state, $location, $window, $injector, $animate, $ionicNavV
histories = $rootScope.$viewHistory.histories,
currentView = $rootScope.$viewHistory.currentView;

for(var historyId in histories) {
if(histories) {
for(var historyId in histories) {

if(histories[historyId].stack) {
histories[historyId].stack = [];
histories[historyId].cursor = -1;
}
if(histories[historyId].stack) {
histories[historyId].stack = [];
histories[historyId].cursor = -1;
}

if(currentView.historyId === historyId) {
currentView.backViewId = null;
currentView.forwardViewId = null;
histories[historyId].stack.push(currentView);
} else if(histories[historyId].destroy) {
histories[historyId].destroy();
}
if(currentView && currentView.historyId === historyId) {
currentView.backViewId = null;
currentView.forwardViewId = null;
histories[historyId].stack.push(currentView);
} else if(histories[historyId].destroy) {
histories[historyId].destroy();
}

}
}

for(var viewId in $rootScope.$viewHistory.views) {
Expand All @@ -573,7 +575,9 @@ function($rootScope, $state, $location, $window, $injector, $animate, $ionicNavV
}
}

this.setNavViews(currentView.viewId);
if(currentView) {
this.setNavViews(currentView.viewId);
}
}

};
Expand Down
4 changes: 4 additions & 0 deletions test/unit/angular/service/viewService.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,10 @@ describe('Ionic View Service', function() {
});
}));

it('should not error when clearing empty history', function() {
expect(viewService.clearHistory.bind(null)).not.toThrow();
});

it('should create a viewService view', inject(function($location) {
var newView = viewService.createView();
expect(newView).toEqual(null);
Expand Down

0 comments on commit 64641b1

Please sign in to comment.