MCPcopy Create free account
hub / github.com/angular-ui/ui-grid / addInterceptor

Function addInterceptor

lib/test/angular/1.6.7/angular.js:16742–16785  ·  view source on GitHub ↗
(parsedExpression, interceptorFn)

Source from the content-addressed store, hash-verified

16740 }
16741
16742 function addInterceptor(parsedExpression, interceptorFn) {
16743 if (!interceptorFn) return parsedExpression;
16744 var watchDelegate = parsedExpression.$$watchDelegate;
16745 var useInputs = false;
16746
16747 var regularWatch =
16748 watchDelegate !== oneTimeLiteralWatchDelegate &&
16749 watchDelegate !== oneTimeWatchDelegate;
16750
16751 var fn = regularWatch ? function regularInterceptedExpression(scope, locals, assign, inputs) {
16752 var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs);
16753 return interceptorFn(value, scope, locals);
16754 } : function oneTimeInterceptedExpression(scope, locals, assign, inputs) {
16755 var value = parsedExpression(scope, locals, assign, inputs);
16756 var result = interceptorFn(value, scope, locals);
16757 // we only return the interceptor's result if the
16758 // initial value is defined (for bind-once)
16759 return isDefined(value) ? result : value;
16760 };
16761
16762 // Propagate $$watchDelegates other then inputsWatchDelegate
16763 useInputs = !parsedExpression.inputs;
16764 if (watchDelegate && watchDelegate !== inputsWatchDelegate) {
16765 fn.$$watchDelegate = watchDelegate;
16766 fn.inputs = parsedExpression.inputs;
16767 } else if (!interceptorFn.$stateful) {
16768 // Treat interceptor like filters - assume non-stateful by default and use the inputsWatchDelegate
16769 fn.$$watchDelegate = inputsWatchDelegate;
16770 fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression];
16771 }
16772
16773 if (fn.inputs) {
16774 fn.inputs = fn.inputs.map(function(e) {
16775 // Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a
16776 // potentially non-pure interceptor function.
16777 if (e.isPure === PURITY_RELATIVE) {
16778 return function depurifier(s) { return e(s); };
16779 }
16780 return e;
16781 });
16782 }
16783
16784 return fn;
16785 }
16786 }];
16787}
16788

Callers 1

$parseFunction · 0.70

Calls 2

eFunction · 0.85
isDefinedFunction · 0.70

Tested by

no test coverage detected