MCPcopy
hub / github.com/angular-ui/ui-grid / addInterceptor

Function addInterceptor

lib/test/angular/1.7.0/angular.js:16968–17014  ·  view source on GitHub ↗
(parsedExpression, interceptorFn)

Source from the content-addressed store, hash-verified

16966 }
16967
16968 function addInterceptor(parsedExpression, interceptorFn) {
16969 if (!interceptorFn) return parsedExpression;
16970
16971 // Extract any existing interceptors out of the parsedExpression
16972 // to ensure the original parsedExpression is always the $$intercepted
16973 if (parsedExpression.$$interceptor) {
16974 interceptorFn = chainInterceptors(parsedExpression.$$interceptor, interceptorFn);
16975 parsedExpression = parsedExpression.$$intercepted;
16976 }
16977
16978 var useInputs = false;
16979
16980 var fn = function interceptedExpression(scope, locals, assign, inputs) {
16981 var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs);
16982 return interceptorFn(value);
16983 };
16984
16985 // Maintain references to the interceptor/intercepted
16986 fn.$$intercepted = parsedExpression;
16987 fn.$$interceptor = interceptorFn;
16988
16989 // Propogate the literal/oneTime/constant attributes
16990 fn.literal = parsedExpression.literal;
16991 fn.oneTime = parsedExpression.oneTime;
16992 fn.constant = parsedExpression.constant;
16993
16994 // Treat the interceptor like filters.
16995 // If it is not $stateful then only watch its inputs.
16996 // If the expression itself has no inputs then use the full expression as an input.
16997 if (!interceptorFn.$stateful) {
16998 useInputs = !parsedExpression.inputs;
16999 fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression];
17000
17001 if (!interceptorFn.$$pure) {
17002 fn.inputs = fn.inputs.map(function(e) {
17003 // Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a
17004 // non-pure interceptor function.
17005 if (e.isPure === PURITY_RELATIVE) {
17006 return function depurifier(s) { return e(s); };
17007 }
17008 return e;
17009 });
17010 }
17011 }
17012
17013 return addWatchDelegate(fn);
17014 }
17015 }];
17016}
17017

Callers 1

$parseFunction · 0.70

Calls 3

eFunction · 0.85
chainInterceptorsFunction · 0.70
addWatchDelegateFunction · 0.70

Tested by

no test coverage detected