refactor(tabs): prevent unnecessary updates during destroy

If the containing ionTabs directive is being destroyed, then child
ionTab directives should not don't bother going through its
controller’s `remove` method, which selects a new active tab as each
ionTab is being destroyed. By selecting a new active tab as each tab is
removed, it causes unnecessary view loads, transitions and multiple
`viewState.changeHistory` events.
This commit is contained in:
Adam Bradley
2014-09-12 23:05:27 -05:00
parent 8883c6ccc5
commit db83d6638e
2 changed files with 18 additions and 5 deletions

View File

@@ -98,7 +98,13 @@ function($rootScope, $animate, $ionicBind, $compile) {
tabsCtrl.add($scope);
$scope.$on('$destroy', function() {
tabsCtrl.remove($scope);
if(!$scope.$tabsDestory) {
// if the containing ionTabs directive is being destroyed
// then don't bother going through the controllers remove
// method, since remove will reset the active tab as each tab
// is being destroyed, causing unnecessary view loads and transitions
tabsCtrl.remove($scope);
}
tabNavElement.isolateScope().$destroy();
tabNavElement.remove();
});

View File

@@ -50,9 +50,9 @@ IonicModule.constant('$ionicTabsConfig', {
IonicModule
.directive('ionTabs', [
'$ionicViewService',
'$ionicTabsDelegate',
'$ionicTabsConfig',
'$ionicViewService',
'$ionicTabsDelegate',
'$ionicTabsConfig',
function($ionicViewService, $ionicTabsDelegate, $ionicTabsConfig) {
return {
restrict: 'E',
@@ -74,7 +74,14 @@ function($ionicViewService, $ionicTabsDelegate, $ionicTabsConfig) {
tabsCtrl, $attr.delegateHandle
);
$scope.$on('$destroy', deregisterInstance);
$scope.$on('$destroy', function(){
// variable to inform child tabs that they're all being blown away
// used so that while destorying an individual tab, each one
// doesn't select the next tab as the active one, which causes unnecessary
// loading of tab views when each will eventually all go away anyway
$scope.$tabsDestory = true;
deregisterInstance();
});
tabsCtrl.$scope = $scope;
tabsCtrl.$element = $element;