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

Commit 65ff861

Browse files
committed
perf($compile): update one-way bindings to no longer use deepWatch for literals
BREAKING CHANGE: Previously when a literal value was passed into a directive/component via one-way binding it would be watched with a deep watcher. For example, for `<my-component input="[a]">`, a new instance of the array would be passed into the directive/component (and trigger $onChanges) not only if `a` changed but also if any sub property of `a` changed such as `a.b` or `a.b.c.d.e` etc. This also means a new but equal value for `a` would NOT trigger such a change. Now literal values use a non-deep watch similar to other directive/component one-way bindings. Changes are only trigger when the value itself changes. Avoiding deep watchers for array/object literals will improve watcher performance of all literals passed as one-way bindings, especially those containing references to large/complex objects.
1 parent c175619 commit 65ff861

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3522,7 +3522,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
35223522
}
35233523
recordChanges(scopeName, newValue, oldValue);
35243524
destination[scopeName] = newValue;
3525-
}, deepWatch);
3525+
});
35263526

35273527
removeWatchCollection.push(removeWatch);
35283528
break;

test/ng/compileSpec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5676,7 +5676,7 @@ describe('$compile', function() {
56765676
}));
56775677

56785678

5679-
it('should deep-watch array literals', inject(function() {
5679+
it('should watch input values to array literals', inject(function() {
56805680
$rootScope.name = 'georgios';
56815681
$rootScope.obj = {name: 'pete'};
56825682
compile('<div><span my-component ow-ref="[{name: name}, obj]">');
@@ -5690,7 +5690,7 @@ describe('$compile', function() {
56905690
}));
56915691

56925692

5693-
it('should deep-watch object literals', inject(function() {
5693+
it('should watch input values object literals', inject(function() {
56945694
$rootScope.name = 'georgios';
56955695
$rootScope.obj = {name: 'pete'};
56965696
compile('<div><span my-component ow-ref="{name: name, item: obj}">');

0 commit comments

Comments
 (0)