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

Function addInterceptor

test/angular/1.7/angular.js:17542–17588  ·  view source on GitHub ↗
(parsedExpression, interceptorFn)

Source from the content-addressed store, hash-verified

17540 }
17541
17542 function addInterceptor(parsedExpression, interceptorFn) {
17543 if (!interceptorFn) return parsedExpression;
17544
17545 // Extract any existing interceptors out of the parsedExpression
17546 // to ensure the original parsedExpression is always the $$intercepted
17547 if (parsedExpression.$$interceptor) {
17548 interceptorFn = chainInterceptors(parsedExpression.$$interceptor, interceptorFn);
17549 parsedExpression = parsedExpression.$$intercepted;
17550 }
17551
17552 var useInputs = false;
17553
17554 var fn = function interceptedExpression(scope, locals, assign, inputs) {
17555 var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs);
17556 return interceptorFn(value);
17557 };
17558
17559 // Maintain references to the interceptor/intercepted
17560 fn.$$intercepted = parsedExpression;
17561 fn.$$interceptor = interceptorFn;
17562
17563 // Propogate the literal/oneTime/constant attributes
17564 fn.literal = parsedExpression.literal;
17565 fn.oneTime = parsedExpression.oneTime;
17566 fn.constant = parsedExpression.constant;
17567
17568 // Treat the interceptor like filters.
17569 // If it is not $stateful then only watch its inputs.
17570 // If the expression itself has no inputs then use the full expression as an input.
17571 if (!interceptorFn.$stateful) {
17572 useInputs = !parsedExpression.inputs;
17573 fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression];
17574
17575 if (!interceptorFn.$$pure) {
17576 fn.inputs = fn.inputs.map(function(e) {
17577 // Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a
17578 // non-pure interceptor function.
17579 if (e.isPure === PURITY_RELATIVE) {
17580 return function depurifier(s) { return e(s); };
17581 }
17582 return e;
17583 });
17584 }
17585 }
17586
17587 return addWatchDelegate(fn);
17588 }
17589 }];
17590}
17591

Callers 1

$parseFunction · 0.70

Calls 2

addWatchDelegateFunction · 0.85
chainInterceptorsFunction · 0.70

Tested by

no test coverage detected