mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix(cache): remove between histories using maxCache(0)
This commit is contained in:
3
js/angular/service/viewSwitcher.js
vendored
3
js/angular/service/viewSwitcher.js
vendored
@@ -178,7 +178,8 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe
|
||||
|
||||
// if the current state has cache:false
|
||||
// or the element has cache-view="false" attribute
|
||||
if (viewState(viewLocals).cache === false || viewState(viewLocals).cache === 'false' || enteringEle.attr('cache-view') == 'false') {
|
||||
if (viewState(viewLocals).cache === false || viewState(viewLocals).cache === 'false' ||
|
||||
enteringEle.attr('cache-view') == 'false' || $ionicConfig.views.maxCache() === 0) {
|
||||
enteringEle.data(DATA_NO_CACHE, true);
|
||||
}
|
||||
|
||||
|
||||
@@ -104,13 +104,27 @@ describe('Ionic nav-view', function() {
|
||||
cache: false
|
||||
},
|
||||
rootView1State = {
|
||||
cache: 'false',
|
||||
views: {
|
||||
'root': {
|
||||
template: '<ion-view>rootView1State</ion-view>'
|
||||
}
|
||||
}
|
||||
},
|
||||
rootView2State = {
|
||||
views: {
|
||||
'root': {
|
||||
template: '<ion-view>rootView2State</ion-view>'
|
||||
}
|
||||
}
|
||||
},
|
||||
rootView1NoCacheState = {
|
||||
cache: 'false',
|
||||
views: {
|
||||
'root': {
|
||||
template: '<ion-view>rootView1NoCacheState</ion-view>'
|
||||
}
|
||||
}
|
||||
},
|
||||
tabAbstractState = {
|
||||
abstract: true,
|
||||
views: {
|
||||
@@ -183,7 +197,9 @@ describe('Ionic nav-view', function() {
|
||||
.state('tabAbstract.tab2page1', tab2page1State)
|
||||
.state('tabAbstract.tab3page1', tab3page1State)
|
||||
.state('tabAbstract.tab3page2', tab3page2NoCacheState)
|
||||
.state('rootView1', rootView1State);
|
||||
.state('rootView1', rootView1State)
|
||||
.state('rootView2', rootView2State)
|
||||
.state('rootView1NoCache', rootView1NoCacheState);
|
||||
}));
|
||||
|
||||
beforeEach(inject(function(_$compile_, $ionicConfig, $rootScope) {
|
||||
@@ -941,9 +957,40 @@ describe('Ionic nav-view', function() {
|
||||
expect(tab3Ele.getAttribute('nav-view')).toBe('cached');
|
||||
}));
|
||||
|
||||
it('should not cache ion-views when going between history and its the first load', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
|
||||
it('should not cache ion-views when going between history and its the first load, stateParam cache=false', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
|
||||
elem.append($compile('<ion-nav-view name="root"></ion-nav-view>')(scope));
|
||||
|
||||
$state.go(rootView1NoCacheState);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
expect(elem.find('ion-nav-view').find('ion-view').length).toBe(1);
|
||||
expect(elem.find('ion-nav-view').find('ion-view').eq(0).text()).toBe('rootView1NoCacheState');
|
||||
|
||||
$state.go(tab1page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
var tab1Ele = elem[0].querySelector('ion-nav-view[name="tab1"]');
|
||||
expect(tab1Ele.getAttribute('nav-view')).toBe('active');
|
||||
|
||||
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
|
||||
|
||||
$state.go(tab2page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
var tab2Ele = elem[0].querySelector('ion-nav-view[name="tab2"]');
|
||||
expect(tab2Ele.getAttribute('nav-view')).toBe('active');
|
||||
|
||||
tab1Ele = elem[0].querySelector('ion-nav-view[name="tab1"]');
|
||||
expect(tab1Ele.getAttribute('nav-view')).toBe('cached');
|
||||
}));
|
||||
|
||||
it('should not cache ion-views when going between history and its the first load, maxCache(0)', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
|
||||
elem.append($compile('<ion-nav-view name="root"></ion-nav-view>')(scope));
|
||||
|
||||
$ionicConfig.views.maxCache(0);
|
||||
|
||||
$state.go(rootView1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
@@ -956,7 +1003,52 @@ describe('Ionic nav-view', function() {
|
||||
|
||||
var tab1Ele = elem[0].querySelector('ion-nav-view[name="tab1"]');
|
||||
expect(tab1Ele.getAttribute('nav-view')).toBe('active');
|
||||
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
|
||||
|
||||
$state.go(tab2page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
|
||||
var tab2Ele = elem[0].querySelector('ion-nav-view[name="tab2"]');
|
||||
expect(tab2Ele.getAttribute('nav-view')).toBe('active');
|
||||
|
||||
tab1Ele = elem[0].querySelector('ion-nav-view[name="tab1"]');
|
||||
expect(tab1Ele).toBe(null);
|
||||
}));
|
||||
|
||||
it('should not cache any views when going root1 to tabs to root 2', inject(function ($state, $q, $timeout, $compile, $ionicConfig) {
|
||||
elem.append($compile('<ion-nav-view name="root"></ion-nav-view>')(scope));
|
||||
|
||||
$ionicConfig.views.maxCache(0);
|
||||
|
||||
$state.go(rootView1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
|
||||
|
||||
$state.go(tab1page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
|
||||
|
||||
$state.go(rootView2State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
|
||||
|
||||
$state.go(rootView1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
|
||||
|
||||
$state.go(tab1page1State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
|
||||
|
||||
$state.go(rootView2State);
|
||||
$q.flush();
|
||||
$timeout.flush();
|
||||
expect(elem[0].querySelector('ion-nav-view[name="root"]').children.length).toBe(1);
|
||||
}));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user