MCPcopy Index your code
hub / github.com/angular-ui/ui-router / addInterceptor

Function addInterceptor

test/angular/1.4/angular.js:14766–14799  ·  view source on GitHub ↗
(parsedExpression, interceptorFn)

Source from the content-addressed store, hash-verified

14764 }
14765
14766 function addInterceptor(parsedExpression, interceptorFn) {
14767 if (!interceptorFn) return parsedExpression;
14768 var watchDelegate = parsedExpression.$$watchDelegate;
14769 var useInputs = false;
14770
14771 var regularWatch =
14772 watchDelegate !== oneTimeLiteralWatchDelegate &&
14773 watchDelegate !== oneTimeWatchDelegate;
14774
14775 var fn = regularWatch ? function regularInterceptedExpression(scope, locals, assign, inputs) {
14776 var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs);
14777 return interceptorFn(value, scope, locals);
14778 } : function oneTimeInterceptedExpression(scope, locals, assign, inputs) {
14779 var value = parsedExpression(scope, locals, assign, inputs);
14780 var result = interceptorFn(value, scope, locals);
14781 // we only return the interceptor's result if the
14782 // initial value is defined (for bind-once)
14783 return isDefined(value) ? result : value;
14784 };
14785
14786 // Propagate $$watchDelegates other then inputsWatchDelegate
14787 if (parsedExpression.$$watchDelegate &&
14788 parsedExpression.$$watchDelegate !== inputsWatchDelegate) {
14789 fn.$$watchDelegate = parsedExpression.$$watchDelegate;
14790 } else if (!interceptorFn.$stateful) {
14791 // If there is an interceptor, but no watchDelegate then treat the interceptor like
14792 // we treat filters - it is assumed to be a pure function unless flagged with $stateful
14793 fn.$$watchDelegate = inputsWatchDelegate;
14794 useInputs = !parsedExpression.inputs;
14795 fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression];
14796 }
14797
14798 return fn;
14799 }
14800 }];
14801}
14802

Callers 1

$parseFunction · 0.70

Calls 1

isDefinedFunction · 0.70

Tested by

no test coverage detected