Skip to content

Commit

Permalink
fix(delegate): isActiveScope climb parent scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Nov 25, 2014
1 parent 03e634a commit 03d2f1c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
18 changes: 15 additions & 3 deletions js/angular/service/history.js
Expand Up @@ -128,7 +128,7 @@ function($rootScope, $state, $location, $window, $ionicViewSwitcher, $ionicNavVi
// nothing found keep climbing up
parentScope = parentScope.$parent;
}
// no history for for the parent, use the root
// no history for the parent, use the root
return { historyId: 'root', scope: $rootScope };
}

Expand Down Expand Up @@ -642,11 +642,23 @@ function($rootScope, $state, $location, $window, $ionicViewSwitcher, $ionicNavVi
},

isActiveScope: function(scope) {
if (!scope || scope.$$disconnected) return false;
if (!scope) return false;

var climbScope = scope;
var historyId;
while (climbScope) {
if (climbScope.$$disconnected) {
return false;
}
if (!historyId && climbScope.hasOwnProperty('$historyId')) {
historyId = climbScope.$historyId;
}
climbScope = climbScope.$parent;
}

var currentHistoryId = this.currentHistoryId();
if (currentHistoryId) {
return currentHistoryId == (isDefined(scope.$historyId) ? scope.$historyId : 'root');
return currentHistoryId == (historyId || 'root');
}

return true;
Expand Down
24 changes: 24 additions & 0 deletions test/unit/angular/service/history.unit.js
Expand Up @@ -1121,6 +1121,17 @@ describe('Ionic History', function() {
expect(ionicHistory.isActiveScope(scope)).toEqual(false);
});

it('should not be active when parent scope is disconnected', function() {
var scope = {
$parent: {
$parent: {
$$disconnected: true
}
}
};
expect(ionicHistory.isActiveScope(scope)).toEqual(false);
});

it('should be active w/ scope but no current history id', function() {
ionicHistory.registerHistory('1234');
expect(ionicHistory.isActiveScope(scope)).toEqual(true);
Expand All @@ -1137,6 +1148,19 @@ describe('Ionic History', function() {
expect(ionicHistory.isActiveScope(scope)).toEqual(true);
});

it('should be active w/ scopes parent the same history id as current view', function() {
ionicHistory.currentView({
historyId: '123'
});

var scope = {
$parent: {
$historyId: '123'
}
}
expect(ionicHistory.isActiveScope(scope)).toEqual(true);
});

it('should be not active w/ scope different history id as current view', function() {
ionicHistory.currentView({
historyId: '123'
Expand Down

0 comments on commit 03d2f1c

Please sign in to comment.