mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
fix(scope): remove scope $destroy event
This commit is contained in:
parent
63be222326
commit
ac5151a469
5 changed files with 14 additions and 19 deletions
|
|
@ -209,6 +209,11 @@ behavior and migrate your controllers one at a time: <https://gist.github.com/16
|
|||
- before: `scope.$watch('expression', function(scope, newVal, oldVal) {})`
|
||||
- after: `scope.$watch('expression', function(newVal, oldVal, scope) {}, true)`
|
||||
|
||||
- `scope.$destroy` doesn't cause the `$destroy` event to be emitted any more - this event was
|
||||
primarily used by the old forms implementation and is not needed any more. We are considering
|
||||
broadcasting this event in the future, which could then be used by directives and child scopes to
|
||||
be notified of their scope destruction.
|
||||
|
||||
|
||||
## New directives:
|
||||
|
||||
|
|
|
|||
|
|
@ -450,15 +450,12 @@ function $RootScopeProvider(){
|
|||
* scope and its children. Removal also implies that the current scope is eligible for garbage
|
||||
* collection.
|
||||
*
|
||||
* The destructing scope emits an `$destroy` {@link angular.module.ng.$rootScope.Scope#$emit event}.
|
||||
*
|
||||
* The `$destroy()` is usually used by directives such as
|
||||
* {@link angular.module.ng.$compileProvider.directive.ng-repeat ng-repeat} for managing the unrolling of the loop.
|
||||
*
|
||||
*/
|
||||
$destroy: function() {
|
||||
if (this.$root == this) return; // we can't remove the root node;
|
||||
this.$emit('$destroy');
|
||||
var parent = this.$parent;
|
||||
|
||||
if (parent.$$childHead == this) parent.$$childHead = this.$$nextSibling;
|
||||
|
|
|
|||
|
|
@ -317,9 +317,11 @@ describe('ng-view', function() {
|
|||
var createCtrl = function(name) {
|
||||
return function($scope) {
|
||||
log.push('init-' + name);
|
||||
$scope.$on('$destroy', function() {
|
||||
var destroy = $scope.$destroy;
|
||||
$scope.$destroy = function() {
|
||||
log.push('destroy-' + name);
|
||||
});
|
||||
destroy.call($scope);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
|
@ -367,7 +369,11 @@ describe('ng-view', function() {
|
|||
function createController(name) {
|
||||
return function($scope) {
|
||||
log.push('init-' + name);
|
||||
$scope.$on('$destroy', logger('destroy-' + name));
|
||||
var destroy = $scope.$destroy;
|
||||
$scope.$destroy = function() {
|
||||
log.push('destroy-' + name);
|
||||
destroy.call($scope);
|
||||
}
|
||||
$scope.$on('$routeUpdate', logger('route-update'));
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1743,12 +1743,9 @@ describe('$compile', function() {
|
|||
expect(widgetScope.$parent).toEqual($rootScope);
|
||||
expect(transcludeScope.$parent).toEqual($rootScope);
|
||||
|
||||
var removed = 0;
|
||||
$rootScope.$on('$destroy', function() { removed++; });
|
||||
$rootScope.select = false;
|
||||
$rootScope.$apply();
|
||||
expect(element.text()).toEqual('Hello: Misko!');
|
||||
expect(removed).toEqual(1);
|
||||
expect(widgetScope.$$nextSibling).toEqual(null);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -393,16 +393,6 @@ describe('Scope', function() {
|
|||
$rootScope.$digest();
|
||||
expect(log).toEqual('12');
|
||||
}));
|
||||
|
||||
it('should fire a $destroy event', inject(function($rootScope) {
|
||||
var destructedScopes = [];
|
||||
middle.$on('$destroy', function(event) {
|
||||
destructedScopes.push(event.currentScope);
|
||||
});
|
||||
middle.$destroy();
|
||||
expect(destructedScopes).toEqual([middle]);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue