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

Commit 190241b

Browse files
committed
perf($rootScope): mark the $watchCollection interceptor as $pure for literals
... to allow shallow watching literal inputs of any type including non-primitive values.
1 parent 2575de3 commit 190241b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/ng/parse.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1944,6 +1944,7 @@ function $ParseProvider() {
19441944
return second(first(value));
19451945
}
19461946
chainedInterceptor.$stateful = first.$stateful || second.$stateful;
1947+
chainedInterceptor.$pure = first.$pure && second.$pure;
19471948

19481949
return chainedInterceptor;
19491950
}
@@ -1979,14 +1980,18 @@ function $ParseProvider() {
19791980
// If the expression itself has no inputs then use the full expression as an input.
19801981
if (!interceptorFn.$stateful) {
19811982
useInputs = !parsedExpression.inputs;
1982-
fn.inputs = (parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression]).map(function(e) {
1983+
fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression];
1984+
1985+
if (!interceptorFn.$pure) {
1986+
fn.inputs = fn.inputs.map(function(e) {
19831987
// Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a
1984-
// potentially non-pure interceptor function.
1988+
// non-pure interceptor function.
19851989
if (e.isPure === PURITY_RELATIVE) {
19861990
return function depurifier(s) { return e(s); };
19871991
}
19881992
return e;
19891993
});
1994+
}
19901995
}
19911996

19921997
return addWatchDelegate(fn);

src/ng/rootScope.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,10 @@ function $RootScopeProvider() {
581581
* de-registration function is executed, the internal watch operation is terminated.
582582
*/
583583
$watchCollection: function(obj, listener) {
584-
// Mark it as $stateful to avoid any input-watching and always invoke the interceptor
584+
// Mark literals as $pure to watch literal inputs of any type.
585+
// Mark non literals as $stateful to avoid input-watching and always invoke the interceptor
585586
// since the inputs will most likely be non-simple (like collections!).
586-
// ... unless it is a literal and input-watching may be sufficient.
587-
$watchCollectionInterceptor.$stateful = !$parse(obj).literal;
587+
$watchCollectionInterceptor.$stateful = !($watchCollectionInterceptor.$pure = $parse(obj).literal);
588588

589589
var self = this;
590590
// the current value, updated on each dirty-check run

0 commit comments

Comments
 (0)