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

Commit 6f1e0ba

Browse files
refactor($compile): rename variables to clarify their purpose
Closes #12528
1 parent 540338f commit 6f1e0ba

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

src/ng/compile.js

+16-17
Original file line numberDiff line numberDiff line change
@@ -1967,7 +1967,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19671967

19681968
function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn) {
19691969
var i, ii, linkFn, controller, isolateScope, elementControllers, transcludeFn, $element,
1970-
attrs;
1970+
attrs, removeScopeBindingWatches, removeControllerBindingWatches;
19711971

19721972
if (compileNode === linkNode) {
19731973
attrs = templateAttrs;
@@ -1999,26 +1999,25 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19991999
compile.$$addScopeClass($element, true);
20002000
isolateScope.$$isolateBindings =
20012001
newIsolateScopeDirective.$$isolateBindings;
2002-
var parentWatchDestroyer = initializeDirectiveBindings(scope, attrs, isolateScope,
2002+
removeScopeBindingWatches = initializeDirectiveBindings(scope, attrs, isolateScope,
20032003
isolateScope.$$isolateBindings,
20042004
newIsolateScopeDirective);
2005-
if (parentWatchDestroyer) {
2006-
isolateScope.$on('$destroy', parentWatchDestroyer);
2005+
if (removeScopeBindingWatches) {
2006+
isolateScope.$on('$destroy', removeScopeBindingWatches);
20072007
}
20082008
}
20092009
if (elementControllers) {
20102010
// Initialize bindToController bindings for new/isolate scopes
20112011
var scopeDirective = newIsolateScopeDirective || newScopeDirective;
20122012
var bindings;
20132013
var controllerForBindings;
2014-
var destroyBindings;
20152014
if (scopeDirective && elementControllers[scopeDirective.name]) {
20162015
bindings = scopeDirective.$$bindings.bindToController;
20172016
controller = elementControllers[scopeDirective.name];
20182017

20192018
if (controller && controller.identifier && bindings) {
20202019
controllerForBindings = controller;
2021-
destroyBindings =
2020+
removeControllerBindingWatches =
20222021
initializeDirectiveBindings(scope, attrs, controller.instance,
20232022
bindings, scopeDirective) || noop;
20242023
}
@@ -2034,8 +2033,8 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
20342033
$element.data('$' + i + 'Controller', controllerResult);
20352034
if (controller === controllerForBindings) {
20362035
// Remove and re-install bindToController bindings
2037-
destroyBindings();
2038-
destroyBindings =
2036+
removeControllerBindingWatches();
2037+
removeControllerBindingWatches =
20392038
initializeDirectiveBindings(scope, attrs, controllerResult, bindings, scopeDirective);
20402039
}
20412040
}
@@ -2575,7 +2574,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
25752574
// Set up $watches for isolate scope and controller bindings. This process
25762575
// only occurs for isolate scopes and new scopes with controllerAs.
25772576
function initializeDirectiveBindings(scope, attrs, destination, bindings, directive) {
2578-
var onNewScopeDestroyed;
2577+
var removeWatchCollection;
25792578
forEach(bindings, function(definition, scopeName) {
25802579
var attrName = definition.attrName,
25812580
optional = definition.optional,
@@ -2637,14 +2636,14 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26372636
return lastValue = parentValue;
26382637
};
26392638
parentValueWatch.$stateful = true;
2640-
var unwatch;
2639+
var removeWatch;
26412640
if (definition.collection) {
2642-
unwatch = scope.$watchCollection(attrs[attrName], parentValueWatch);
2641+
removeWatch = scope.$watchCollection(attrs[attrName], parentValueWatch);
26432642
} else {
2644-
unwatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal);
2643+
removeWatch = scope.$watch($parse(attrs[attrName], parentValueWatch), null, parentGet.literal);
26452644
}
2646-
onNewScopeDestroyed = (onNewScopeDestroyed || []);
2647-
onNewScopeDestroyed.push(unwatch);
2645+
removeWatchCollection = (removeWatchCollection || []);
2646+
removeWatchCollection.push(removeWatch);
26482647
break;
26492648

26502649
case '&':
@@ -2661,9 +2660,9 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
26612660
}
26622661
});
26632662

2664-
return onNewScopeDestroyed && function destroyBindings() {
2665-
for (var i = 0, ii = onNewScopeDestroyed.length; i < ii; ++i) {
2666-
onNewScopeDestroyed[i]();
2663+
return removeWatchCollection && function removeWatches() {
2664+
for (var i = 0, ii = removeWatchCollection.length; i < ii; ++i) {
2665+
removeWatchCollection[i]();
26672666
}
26682667
};
26692668
}

0 commit comments

Comments
 (0)