Skip to content

Commit 64641b1

Browse files
committed
fix(viewService): No error on clearHistory for empty history
1 parent 5b99fd6 commit 64641b1

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

js/angular/service/viewService.js

+17-13
Original file line numberDiff line numberDiff line change
@@ -550,21 +550,23 @@ function($rootScope, $state, $location, $window, $injector, $animate, $ionicNavV
550550
histories = $rootScope.$viewHistory.histories,
551551
currentView = $rootScope.$viewHistory.currentView;
552552

553-
for(var historyId in histories) {
553+
if(histories) {
554+
for(var historyId in histories) {
554555

555-
if(histories[historyId].stack) {
556-
histories[historyId].stack = [];
557-
histories[historyId].cursor = -1;
558-
}
556+
if(histories[historyId].stack) {
557+
histories[historyId].stack = [];
558+
histories[historyId].cursor = -1;
559+
}
559560

560-
if(currentView.historyId === historyId) {
561-
currentView.backViewId = null;
562-
currentView.forwardViewId = null;
563-
histories[historyId].stack.push(currentView);
564-
} else if(histories[historyId].destroy) {
565-
histories[historyId].destroy();
566-
}
561+
if(currentView && currentView.historyId === historyId) {
562+
currentView.backViewId = null;
563+
currentView.forwardViewId = null;
564+
histories[historyId].stack.push(currentView);
565+
} else if(histories[historyId].destroy) {
566+
histories[historyId].destroy();
567+
}
567568

569+
}
568570
}
569571

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

576-
this.setNavViews(currentView.viewId);
578+
if(currentView) {
579+
this.setNavViews(currentView.viewId);
580+
}
577581
}
578582

579583
};

test/unit/angular/service/viewService.unit.js

+4
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,10 @@ describe('Ionic View Service', function() {
697697
});
698698
}));
699699

700+
it('should not error when clearing empty history', function() {
701+
expect(viewService.clearHistory.bind(null)).not.toThrow();
702+
});
703+
700704
it('should create a viewService view', inject(function($location) {
701705
var newView = viewService.createView();
702706
expect(newView).toEqual(null);

0 commit comments

Comments
 (0)