| 15201 | } |
| 15202 | |
| 15203 | function addInterceptor(parsedExpression, interceptorFn) { |
| 15204 | if (!interceptorFn) return parsedExpression; |
| 15205 | var watchDelegate = parsedExpression.$$watchDelegate; |
| 15206 | var useInputs = false; |
| 15207 | |
| 15208 | var regularWatch = |
| 15209 | watchDelegate !== oneTimeLiteralWatchDelegate && |
| 15210 | watchDelegate !== oneTimeWatchDelegate; |
| 15211 | |
| 15212 | var fn = regularWatch ? function regularInterceptedExpression(scope, locals, assign, inputs) { |
| 15213 | var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs); |
| 15214 | return interceptorFn(value, scope, locals); |
| 15215 | } : function oneTimeInterceptedExpression(scope, locals, assign, inputs) { |
| 15216 | var value = parsedExpression(scope, locals, assign, inputs); |
| 15217 | var result = interceptorFn(value, scope, locals); |
| 15218 | // we only return the interceptor's result if the |
| 15219 | // initial value is defined (for bind-once) |
| 15220 | return isDefined(value) ? result : value; |
| 15221 | }; |
| 15222 | |
| 15223 | // Propagate $$watchDelegates other then inputsWatchDelegate |
| 15224 | if (parsedExpression.$$watchDelegate && |
| 15225 | parsedExpression.$$watchDelegate !== inputsWatchDelegate) { |
| 15226 | fn.$$watchDelegate = parsedExpression.$$watchDelegate; |
| 15227 | } else if (!interceptorFn.$stateful) { |
| 15228 | // If there is an interceptor, but no watchDelegate then treat the interceptor like |
| 15229 | // we treat filters - it is assumed to be a pure function unless flagged with $stateful |
| 15230 | fn.$$watchDelegate = inputsWatchDelegate; |
| 15231 | useInputs = !parsedExpression.inputs; |
| 15232 | fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression]; |
| 15233 | } |
| 15234 | |
| 15235 | return fn; |
| 15236 | } |
| 15237 | }]; |
| 15238 | } |
| 15239 | |