Skip to content

Commit ba2ba82

Browse files
Revert "cherry-pick 1be1379 from 0.2.17"
This reverts commit 94fa6db.
1 parent 81d00ea commit ba2ba82

File tree

2 files changed

+17
-69
lines changed

2 files changed

+17
-69
lines changed

src/ng1/viewDirective.ts

+10-25
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function $ViewDirective( $view, $animate, $uiViewScroll, $interpolate,
177177
trace.traceUiViewEvent("Linking", viewData);
178178

179179
function configUpdatedCallback(config?: ViewConfig) {
180-
if (configsEqual(viewConfig, config) || scope._willBeDestroyed) return;
180+
if (configsEqual(viewConfig, config)) return;
181181
trace.traceUiViewConfigUpdated(viewData, config && config.context);
182182

183183
viewConfig = config;
@@ -195,42 +195,27 @@ function $ViewDirective( $view, $animate, $uiViewScroll, $interpolate,
195195
});
196196

197197
function cleanupLastView() {
198-
var _previousEl = previousEl;
199-
var _currentScope = currentScope;
200-
201-
if (_currentScope) {
202-
_currentScope._willBeDestroyed = true;
198+
if (previousEl) {
199+
trace.traceUiViewEvent("Removing (previous) el", viewData);
200+
previousEl.remove();
201+
previousEl = null;
203202
}
204203

205-
function cleanOld() {
206-
if (_previousEl) {
207-
trace.traceUiViewEvent("Removing (previous) el", viewData);
208-
_previousEl.remove();
209-
_previousEl = null;
210-
}
211-
212-
if (_currentScope) {
213-
trace.traceUiViewEvent("Destroying (previous) scope", viewData);
214-
_currentScope.$destroy();
215-
_currentScope = null;
216-
}
204+
if (currentScope) {
205+
trace.traceUiViewEvent("Destroying (previous) scope", viewData);
206+
currentScope.$destroy();
207+
currentScope = null;
217208
}
218209

219210
if (currentEl) {
220211
trace.traceUiViewEvent("Animate out (previous)", viewData);
221212
renderer.leave(currentEl, function() {
222-
cleanOld();
223213
previousEl = null;
224214
});
225215

226216
previousEl = currentEl;
227-
} else {
228-
cleanOld();
229-
previousEl = null;
217+
currentEl = null;
230218
}
231-
232-
currentEl = null;
233-
currentScope = null;
234219
}
235220

236221
function updateView(config?: ViewConfig) {

test/viewDirectiveSpec.js

+7-44
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function animateFlush($animate) {
1414
describe('uiView', function () {
1515
'use strict';
1616

17-
var log, scope, $compile, elem;
17+
var scope, $compile, elem;
1818

1919
beforeEach(function() {
2020
var depends = ['ui.router'];
@@ -37,10 +37,6 @@ describe('uiView', function () {
3737
});
3838
}));
3939

40-
beforeEach(function() {
41-
log = '';
42-
});
43-
4440
var aState = {
4541
template: 'aState template'
4642
},
@@ -112,9 +108,8 @@ describe('uiView', function () {
112108
}
113109
}
114110
},
115-
116-
oState = {
117-
template: 'oState',
111+
mState = {
112+
template: 'mState',
118113
controller: function ($scope, $element) {
119114
$scope.elementId = $element.attr('id');
120115
}
@@ -134,22 +129,7 @@ describe('uiView', function () {
134129
.state('j', jState)
135130
.state('k', kState)
136131
.state('l', lState)
137-
.state('m', {
138-
template: 'mState',
139-
controller: function($scope) {
140-
log += 'm;';
141-
$scope.$on('$destroy', function() {
142-
log += '$destroy(m);';
143-
});
144-
},
145-
})
146-
.state('n', {
147-
template: 'nState',
148-
controller: function($scope) {
149-
log += 'n;';
150-
},
151-
})
152-
.state('o', oState)
132+
.state('m', mState)
153133
}));
154134

155135
beforeEach(inject(function ($rootScope, _$compile_) {
@@ -160,23 +140,6 @@ describe('uiView', function () {
160140

161141
describe('linking ui-directive', function () {
162142

163-
it('$destroy event is triggered after animation ends', inject(function($state, $q, $animate) {
164-
elem.append($compile('<div><ui-view></ui-view></div>')(scope));
165-
166-
$state.transitionTo('m');
167-
$q.flush();
168-
expect(log).toBe('m;');
169-
$state.transitionTo('n');
170-
$q.flush();
171-
if ($animate) {
172-
expect(log).toBe('m;n;');
173-
animateFlush($animate);
174-
expect(log).toBe('m;n;$destroy(m);');
175-
} else {
176-
expect(log).toBe('m;$destroy(m);n;');
177-
}
178-
}));
179-
180143
it('anonymous ui-view should be replaced with the template of the current $state', inject(function ($state, $q) {
181144
elem.append($compile('<div><ui-view></ui-view></div>')(scope));
182145

@@ -362,11 +325,11 @@ describe('uiView', function () {
362325
}));
363326

364327
it('should instantiate a controller with both $scope and $element injections', inject(function ($state, $q) {
365-
elem.append($compile('<div><ui-view id="oState">{{elementId}}</ui-view></div>')(scope));
366-
$state.transitionTo(oState);
328+
elem.append($compile('<div><ui-view id="mState">{{elementId}}</ui-view></div>')(scope));
329+
$state.transitionTo(mState);
367330
$q.flush();
368331

369-
expect(elem.text()).toBe('oState');
332+
expect(elem.text()).toBe('mState');
370333
}));
371334

372335
describe('play nicely with other directives', function() {

0 commit comments

Comments
 (0)