Skip to content

Commit 3c74c3a

Browse files
committed
refactor($parse): don't use bind-once interceptor for non-bind-once expressions
Side-effects: - Logic for allOrNothing watches now lives in $intercept rather than $parse Credit to @jbedard for idea to remove $watch interceptors craziness from $interpolate. Closes angular#9958
1 parent 8582088 commit 3c74c3a

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/ng/interpolate.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ function $InterpolateProvider() {
301301

302302
function parseStringifyInterceptor(value) {
303303
try {
304-
return stringify(getValue(value));
304+
value = getValue(value);
305+
return allOrNothing ? value : stringify(value);
305306
} catch (err) {
306307
var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text,
307308
err.toString());

src/ng/parse.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,21 @@ function $ParseProvider() {
12531253

12541254
function addInterceptor(parsedExpression, interceptorFn) {
12551255
if (!interceptorFn) return parsedExpression;
1256+
var watchDelegate = parsedExpression.$$watchDelegate;
12561257

1257-
var fn = function interceptedExpression(scope, locals) {
1258+
var regularWatch =
1259+
watchDelegate !== oneTimeLiteralWatchDelegate &&
1260+
watchDelegate !== oneTimeWatchDelegate;
1261+
1262+
var fn = regularWatch ? function regularInterceptedExpression(scope, locals) {
1263+
var value = parsedExpression(scope, locals);
1264+
return interceptorFn(value, scope, locals);
1265+
} : function oneTimeInterceptedExpression(scope, locals) {
12581266
var value = parsedExpression(scope, locals);
12591267
var result = interceptorFn(value, scope, locals);
12601268
// we only return the interceptor's result if the
12611269
// initial value is defined (for bind-once)
1262-
return isDefined(value) || interceptorFn.$stateful ? result : value;
1270+
return isDefined(value) ? result : value;
12631271
};
12641272

12651273
// Propagate $$watchDelegates other then inputsWatchDelegate

0 commit comments

Comments
 (0)