| 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 | |