aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2012-03-12 23:40:19 -0700
committerIgor Minar2012-03-13 14:13:53 -0700
commitac5151a469667b1cc1b5e2f96d330b71631efd0b (patch)
tree451940a5803d72784e4e703975b28a75cf2457cd
parent63be222326f3badbb76371f82d49fed5ab9e3e65 (diff)
downloadangular.js-ac5151a469667b1cc1b5e2f96d330b71631efd0b.tar.bz2
fix(scope): remove scope $destroy event
-rw-r--r--CHANGELOG.md5
-rw-r--r--src/service/scope.js3
-rw-r--r--test/directive/ngViewSpec.js12
-rw-r--r--test/service/compilerSpec.js3
-rw-r--r--test/service/scopeSpec.js10
5 files changed, 14 insertions, 19 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 985f4459..8fdb8231 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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:
diff --git a/src/service/scope.js b/src/service/scope.js
index 24313620..ef1b7b93 100644
--- a/src/service/scope.js
+++ b/src/service/scope.js
@@ -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;
diff --git a/test/directive/ngViewSpec.js b/test/directive/ngViewSpec.js
index 2a4347a0..7b702e51 100644
--- a/test/directive/ngViewSpec.js
+++ b/test/directive/ngViewSpec.js
@@ -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'));
};
}
diff --git a/test/service/compilerSpec.js b/test/service/compilerSpec.js
index a9d0a5db..b42b871a 100644
--- a/test/service/compilerSpec.js
+++ b/test/service/compilerSpec.js
@@ -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);
});
});
diff --git a/test/service/scopeSpec.js b/test/service/scopeSpec.js
index d3713e9d..95b028fe 100644
--- a/test/service/scopeSpec.js
+++ b/test/service/scopeSpec.js
@@ -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]);
- }));
-
});