| 16925 | } |
| 16926 | |
| 16927 | function addInterceptor(parsedExpression, interceptorFn) { |
| 16928 | if (!interceptorFn) return parsedExpression; |
| 16929 | var watchDelegate = parsedExpression.$$watchDelegate; |
| 16930 | var useInputs = false; |
| 16931 | |
| 16932 | var regularWatch = |
| 16933 | watchDelegate !== oneTimeLiteralWatchDelegate && |
| 16934 | watchDelegate !== oneTimeWatchDelegate; |
| 16935 | |
| 16936 | var fn = regularWatch ? function regularInterceptedExpression(scope, locals, assign, inputs) { |
| 16937 | var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs); |
| 16938 | return interceptorFn(value, scope, locals); |
| 16939 | } : function oneTimeInterceptedExpression(scope, locals, assign, inputs) { |
| 16940 | var value = parsedExpression(scope, locals, assign, inputs); |
| 16941 | var result = interceptorFn(value, scope, locals); |
| 16942 | // we only return the interceptor's result if the |
| 16943 | // initial value is defined (for bind-once) |
| 16944 | return isDefined(value) ? result : value; |
| 16945 | }; |
| 16946 | |
| 16947 | // Propagate $$watchDelegates other then inputsWatchDelegate |
| 16948 | useInputs = !parsedExpression.inputs; |
| 16949 | if (watchDelegate && watchDelegate !== inputsWatchDelegate) { |
| 16950 | fn.$$watchDelegate = watchDelegate; |
| 16951 | fn.inputs = parsedExpression.inputs; |
| 16952 | } else if (!interceptorFn.$stateful) { |
| 16953 | // Treat interceptor like filters - assume non-stateful by default and use the inputsWatchDelegate |
| 16954 | fn.$$watchDelegate = inputsWatchDelegate; |
| 16955 | fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression]; |
| 16956 | } |
| 16957 | |
| 16958 | if (fn.inputs) { |
| 16959 | fn.inputs = fn.inputs.map(function(e) { |
| 16960 | // Remove the isPure flag of inputs when it is not absolute because they are now wrapped in a |
| 16961 | // potentially non-pure interceptor function. |
| 16962 | if (e.isPure === PURITY_RELATIVE) { |
| 16963 | return function depurifier(s) { return e(s); }; |
| 16964 | } |
| 16965 | return e; |
| 16966 | }); |
| 16967 | } |
| 16968 | |
| 16969 | return fn; |
| 16970 | } |
| 16971 | }]; |
| 16972 | } |
| 16973 | |