Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 9f210a5

Browse files
committed
refactor($compile): remove unnecessary and invalid $destroyed listener
1 parent ed3a33a commit 9f210a5

File tree

1 file changed

+19
-28
lines changed

1 file changed

+19
-28
lines changed

src/ng/compile.js

+19-28
Original file line numberDiff line numberDiff line change
@@ -1416,11 +1416,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
14161416
if (nodeLinkFn.scope) {
14171417
childScope = scope.$new();
14181418
compile.$$addScopeInfo(jqLite(node), childScope);
1419-
var destroyBindings = nodeLinkFn.$$destroyBindings;
1420-
if (destroyBindings) {
1421-
nodeLinkFn.$$destroyBindings = null;
1422-
childScope.$on('$destroyed', destroyBindings);
1423-
}
14241419
} else {
14251420
childScope = scope;
14261421
}
@@ -1439,8 +1434,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
14391434
childBoundTranscludeFn = null;
14401435
}
14411436

1442-
nodeLinkFn(childLinkFn, childScope, node, $rootElement, childBoundTranscludeFn,
1443-
nodeLinkFn);
1437+
nodeLinkFn(childLinkFn, childScope, node, $rootElement, childBoundTranscludeFn);
14441438

14451439
} else if (childLinkFn) {
14461440
childLinkFn(scope, node.childNodes, undefined, parentBoundTranscludeFn);
@@ -1950,8 +1944,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19501944
return elementControllers;
19511945
}
19521946

1953-
function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn,
1954-
thisLinkFn) {
1947+
function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn) {
19551948
var i, ii, linkFn, controller, isolateScope, elementControllers, transcludeFn, $element,
19561949
attrs;
19571950

@@ -1985,24 +1978,28 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19851978
compile.$$addScopeClass($element, true);
19861979
isolateScope.$$isolateBindings =
19871980
newIsolateScopeDirective.$$isolateBindings;
1988-
initializeDirectiveBindings(scope, attrs, isolateScope,
1989-
isolateScope.$$isolateBindings,
1990-
newIsolateScopeDirective, isolateScope);
1981+
var parentWatchDestoryer = initializeDirectiveBindings(scope, attrs, isolateScope,
1982+
isolateScope.$$isolateBindings,
1983+
newIsolateScopeDirective);
1984+
if (parentWatchDestoryer) {
1985+
isolateScope.$on('$destroy', parentWatchDestoryer);
1986+
}
19911987
}
19921988
if (elementControllers) {
19931989
// Initialize bindToController bindings for new/isolate scopes
19941990
var scopeDirective = newIsolateScopeDirective || newScopeDirective;
19951991
var bindings;
19961992
var controllerForBindings;
1993+
var destroyBindings;
19971994
if (scopeDirective && elementControllers[scopeDirective.name]) {
19981995
bindings = scopeDirective.$$bindings.bindToController;
19991996
controller = elementControllers[scopeDirective.name];
20001997

20011998
if (controller && controller.identifier && bindings) {
20021999
controllerForBindings = controller;
2003-
thisLinkFn.$$destroyBindings =
2000+
destroyBindings =
20042001
initializeDirectiveBindings(scope, attrs, controller.instance,
2005-
bindings, scopeDirective);
2002+
bindings, scopeDirective) || noop;
20062003
}
20072004
}
20082005
for (i in elementControllers) {
@@ -2016,8 +2013,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
20162013
$element.data('$' + i + 'Controller', controllerResult);
20172014
if (controller === controllerForBindings) {
20182015
// Remove and re-install bindToController bindings
2019-
thisLinkFn.$$destroyBindings();
2020-
thisLinkFn.$$destroyBindings =
2016+
destroyBindings();
2017+
destroyBindings =
20212018
initializeDirectiveBindings(scope, attrs, controllerResult, bindings, scopeDirective);
20222019
}
20232020
}
@@ -2279,7 +2276,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
22792276
childBoundTranscludeFn = boundTranscludeFn;
22802277
}
22812278
afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, linkNode, $rootElement,
2282-
childBoundTranscludeFn, afterTemplateNodeLinkFn);
2279+
childBoundTranscludeFn);
22832280
}
22842281
linkQueue = null;
22852282
});
@@ -2296,8 +2293,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
22962293
if (afterTemplateNodeLinkFn.transcludeOnThisElement) {
22972294
childBoundTranscludeFn = createBoundTranscludeFn(scope, afterTemplateNodeLinkFn.transclude, boundTranscludeFn);
22982295
}
2299-
afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, childBoundTranscludeFn,
2300-
afterTemplateNodeLinkFn);
2296+
afterTemplateNodeLinkFn(afterTemplateChildLinkFn, scope, node, rootElement, childBoundTranscludeFn);
23012297
}
23022298
};
23032299
}
@@ -2557,8 +2553,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
25572553

25582554
// Set up $watches for isolate scope and controller bindings. This process
25592555
// only occurs for isolate scopes and new scopes with controllerAs.
2560-
function initializeDirectiveBindings(scope, attrs, destination, bindings,
2561-
directive, newScope) {
2556+
function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) {
25622557
var onNewScopeDestroyed;
25632558
forEach(bindings, function(definition, scopeName) {
25642559
var attrName = definition.attrName,
@@ -2644,16 +2639,12 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26442639
break;
26452640
}
26462641
});
2647-
var destroyBindings = onNewScopeDestroyed ? function destroyBindings() {
2642+
2643+
return onNewScopeDestroyed && function destroyBindings() {
26482644
for (var i = 0, ii = onNewScopeDestroyed.length; i < ii; ++i) {
26492645
onNewScopeDestroyed[i]();
26502646
}
2651-
} : noop;
2652-
if (newScope && destroyBindings !== noop) {
2653-
newScope.$on('$destroy', destroyBindings);
2654-
return noop;
2655-
}
2656-
return destroyBindings;
2647+
};
26572648
}
26582649
}];
26592650
}

0 commit comments

Comments
 (0)