Skip to content

Commit 6410e1f

Browse files
committed
Merge branch 'master' of github.com:driftyco/ionic
2 parents 11e1bab + 129e69b commit 6410e1f

File tree

3 files changed

+44
-9
lines changed

3 files changed

+44
-9
lines changed

js/angular/controller/navViewController.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
1313

1414
var DATA_ELE_IDENTIFIER = '$eleId';
1515
var DATA_DESTROY_ELE = '$destroyEle';
16+
var DATA_NO_CACHE = '$noCache';
1617
var VIEW_STATUS_ACTIVE = 'active';
1718
var VIEW_STATUS_CACHED = 'cached';
1819
var HISTORY_AFTER_ROOT = 'after-root';
@@ -132,26 +133,32 @@ function($scope, $element, $attrs, $compile, $controller, $ionicNavBarDelegate,
132133

133134
self.transitionEnd = function() {
134135
var viewElements = $element.children();
135-
var viewElementsLength = viewElements.length;
136-
var x, viewElement;
136+
var x, l, viewElement;
137137
var isHistoryRoot;
138138

139-
for (x = 0; x < viewElementsLength; x++) {
139+
for (x = 0, l = viewElements.length; x < l; x++) {
140140
viewElement = viewElements.eq(x);
141141

142142
if (viewElement.data(DATA_ELE_IDENTIFIER) === activeEleId) {
143143
// this is the active element
144144
navViewAttr(viewElement, VIEW_STATUS_ACTIVE);
145145
isHistoryRoot = $ionicViewSwitcher.isHistoryRoot(viewElement);
146146

147-
} else if (navViewAttr(viewElement) === 'leaving' || navViewAttr(viewElement) === VIEW_STATUS_ACTIVE) {
148-
// this is a leaving element or was the former active element
149-
navViewAttr(viewElement, VIEW_STATUS_CACHED);
147+
} else if (navViewAttr(viewElement) === 'leaving' || navViewAttr(viewElement) === VIEW_STATUS_ACTIVE || navViewAttr(viewElement) === VIEW_STATUS_CACHED) {
148+
// this is a leaving element or was the former active element, or is an cached element
149+
if (viewElement.data(DATA_DESTROY_ELE) || viewElement.data(DATA_NO_CACHE)) {
150+
// this element shouldn't stay cached
151+
$ionicViewSwitcher.destroyViewEle(viewElement);
152+
} else {
153+
// keep in the DOM, mark as cached
154+
navViewAttr(viewElement, VIEW_STATUS_CACHED);
155+
}
150156
}
151157
}
152158

153159
if (isHistoryRoot) {
154-
for (x = 0; x < viewElementsLength; x++) {
160+
viewElements = $element.children();
161+
for (x = 0, l = viewElements.length; x < l; x++) {
155162
viewElement = viewElements.eq(x);
156163

157164
if ($ionicViewSwitcher.isHistoryRoot(viewElement) && navViewAttr(viewElement) !== VIEW_STATUS_ACTIVE) {

js/angular/service/viewSwitcher.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe
184184

185185
// if the current state has cache:false
186186
// or the element has cache-view="false" attribute
187-
if (viewState(viewLocals).cache === false || enteringEle.attr('cache-view') == 'false') {
187+
if (viewState(viewLocals).cache === false || viewState(viewLocals).cache === 'false' || enteringEle.attr('cache-view') == 'false') {
188188
enteringEle.data(DATA_NO_CACHE, true);
189189
}
190190

test/unit/angular/directive/navView.unit.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ describe('Ionic nav-view', function() {
103103
template: '<ion-view>ionViewCacheFalsePropertyState</ion-view>',
104104
cache: false
105105
},
106+
rootView1State = {
107+
cache: 'false',
108+
views: {
109+
'root': {
110+
template: '<ion-view>rootView1State</ion-view>'
111+
}
112+
}
113+
},
106114
tabAbstractState = {
107115
abstract: true,
108116
views: {
@@ -174,7 +182,8 @@ describe('Ionic nav-view', function() {
174182
.state('tabAbstract.tab1page1', tab1page1State)
175183
.state('tabAbstract.tab2page1', tab2page1State)
176184
.state('tabAbstract.tab3page1', tab3page1State)
177-
.state('tabAbstract.tab3page2', tab3page2NoCacheState);
185+
.state('tabAbstract.tab3page2', tab3page2NoCacheState)
186+
.state('rootView1', rootView1State);
178187
}));
179188

180189
beforeEach(inject(function(_$compile_, $ionicConfig, $rootScope) {
@@ -932,6 +941,25 @@ describe('Ionic nav-view', function() {
932941
expect(tab3Ele.getAttribute('nav-view')).toBe('cached');
933942
}));
934943

944+
it('should not cache ion-views when going between history and its the first load', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
945+
elem.append($compile('<ion-nav-view name="root"></ion-nav-view>')(scope));
946+
947+
$state.go(rootView1State);
948+
$q.flush();
949+
$timeout.flush();
950+
expect(elem.find('ion-nav-view').find('ion-view').length).toBe(1);
951+
expect(elem.find('ion-nav-view').find('ion-view').eq(0).text()).toBe('rootView1State');
952+
953+
$state.go(tab1page1State);
954+
$q.flush();
955+
$timeout.flush();
956+
957+
var tab1Ele = elem[0].querySelector('ion-nav-view[name="tab1"]');
958+
expect(tab1Ele.getAttribute('nav-view')).toBe('active');
959+
960+
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
961+
}));
962+
935963
it('should not cache a tab with cache false state property', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
936964
elem.append($compile('<ion-nav-view name="root"></ion-nav-view>')(scope));
937965

0 commit comments

Comments
 (0)