| 16342 | } |
| 16343 | |
| 16344 | function addInterceptor(parsedExpression, interceptorFn) { |
| 16345 | if (!interceptorFn) return parsedExpression; |
| 16346 | var watchDelegate = parsedExpression.$$watchDelegate; |
| 16347 | var useInputs = false; |
| 16348 | |
| 16349 | var regularWatch = |
| 16350 | watchDelegate !== oneTimeLiteralWatchDelegate && |
| 16351 | watchDelegate !== oneTimeWatchDelegate; |
| 16352 | |
| 16353 | var fn = regularWatch ? function regularInterceptedExpression(scope, locals, assign, inputs) { |
| 16354 | var value = useInputs && inputs ? inputs[0] : parsedExpression(scope, locals, assign, inputs); |
| 16355 | return interceptorFn(value, scope, locals); |
| 16356 | } : function oneTimeInterceptedExpression(scope, locals, assign, inputs) { |
| 16357 | var value = parsedExpression(scope, locals, assign, inputs); |
| 16358 | var result = interceptorFn(value, scope, locals); |
| 16359 | // we only return the interceptor's result if the |
| 16360 | // initial value is defined (for bind-once) |
| 16361 | return isDefined(value) ? result : value; |
| 16362 | }; |
| 16363 | |
| 16364 | // Propagate $$watchDelegates other then inputsWatchDelegate |
| 16365 | if (parsedExpression.$$watchDelegate && |
| 16366 | parsedExpression.$$watchDelegate !== inputsWatchDelegate) { |
| 16367 | fn.$$watchDelegate = parsedExpression.$$watchDelegate; |
| 16368 | } else if (!interceptorFn.$stateful) { |
| 16369 | // If there is an interceptor, but no watchDelegate then treat the interceptor like |
| 16370 | // we treat filters - it is assumed to be a pure function unless flagged with $stateful |
| 16371 | fn.$$watchDelegate = inputsWatchDelegate; |
| 16372 | useInputs = !parsedExpression.inputs; |
| 16373 | fn.inputs = parsedExpression.inputs ? parsedExpression.inputs : [parsedExpression]; |
| 16374 | } |
| 16375 | |
| 16376 | return fn; |
| 16377 | } |
| 16378 | }]; |
| 16379 | } |
| 16380 | |