perf($rootScope): allow $watchCollection use of expression input watching
By adding a $$pure flag to the $watchCollectionInterceptor to shallow watch all inputs regardless of type when watching an object/array literal.
This commit is contained in:
+7
-2
@@ -1944,6 +1944,7 @@ function $ParseProvider() {
|
||||
return second(first(value));
|
||||
}
|
||||
chainedInterceptor.$stateful = first.$stateful || second.$stateful;
|
||||
chainedInterceptor.$$pure = first.$$pure && second.$$pure;
|
||||
|
||||
return chainedInterceptor;
|
||||
}
|
||||
@@ -1979,14 +1980,18 @@ function $ParseProvider() {
|
||||
// If the expression itself has no inputs then use the full expression as an input.
|
||||
if (!interceptorFn.$stateful) {
|
||||
useInputs = !parsedExpression.inputs;
|
||||
fn.inputs = (parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression]).map(function(e) {
|
||||
fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression];
|
||||
|
||||
if (!interceptorFn.$$pure) {
|
||||
fn.inputs = fn.inputs.map(function(e) {
|
||||
// Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a
|
||||
// potentially non-pure interceptor function.
|
||||
// non-pure interceptor function.
|
||||
if (e.isPure === PURITY_RELATIVE) {
|
||||
return function depurifier(s) { return e(s); };
|
||||
}
|
||||
return e;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return addWatchDelegate(fn);
|
||||
|
||||
+5
-1
@@ -581,7 +581,11 @@ function $RootScopeProvider() {
|
||||
* de-registration function is executed, the internal watch operation is terminated.
|
||||
*/
|
||||
$watchCollection: function(obj, listener) {
|
||||
$watchCollectionInterceptor.$stateful = true;
|
||||
// Mark the interceptor as
|
||||
// ... $$pure when literal since the instance will change when any input changes
|
||||
$watchCollectionInterceptor.$$pure = $parse(obj).literal;
|
||||
// ... $stateful when non-literal since we must read the state of the collection
|
||||
$watchCollectionInterceptor.$stateful = !$watchCollectionInterceptor.$$pure;
|
||||
|
||||
var self = this;
|
||||
// the current value, updated on each dirty-check run
|
||||
|
||||
Reference in New Issue
Block a user