Skip to content

Commit 83ce6aa

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 Closes angular#9958
1 parent 1db9e61 commit 83ce6aa

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

src/ng/compile.js

-1
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
19361936
}
19371937
return lastValue = parentValue;
19381938
};
1939-
parentValueWatch.$stateful = true;
19401939
var unwatch;
19411940
if (definition.collection) {
19421941
unwatch = scope.$watchCollection(attrs[attrName], parentValueWatch);

src/ng/interpolate.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ function $InterpolateProvider() {
192192
textLength = text.length,
193193
exp,
194194
concat = [],
195-
expressionPositions = [];
195+
expressionPositions = [],
196+
interceptor = allOrNothing ? allOrNothingParseStringifyInterceptor :
197+
parseStringifyInterceptor;
196198

197199
while (index < textLength) {
198200
if (((startIndex = text.indexOf(startSymbol, index)) != -1) &&
@@ -202,7 +204,7 @@ function $InterpolateProvider() {
202204
}
203205
exp = text.substring(startIndex + startSymbolLength, endIndex);
204206
expressions.push(exp);
205-
parseFns.push($parse(exp, parseStringifyInterceptor));
207+
parseFns.push($parse(exp, interceptor));
206208
index = endIndex + endSymbolLength;
207209
expressionPositions.push(concat.length);
208210
concat.push('');
@@ -231,7 +233,9 @@ function $InterpolateProvider() {
231233
if (!mustHaveExpression || expressions.length) {
232234
var compute = function(values) {
233235
for (var i = 0, ii = expressions.length; i < ii; i++) {
234-
if (allOrNothing && isUndefined(values[i])) return;
236+
if (allOrNothing && isUndefined(values[i])) {
237+
return;
238+
}
235239
concat[expressionPositions[i]] = values[i];
236240
}
237241
return concat.join('');
@@ -308,6 +312,20 @@ function $InterpolateProvider() {
308312
$exceptionHandler(newErr);
309313
}
310314
}
315+
316+
function allOrNothingParseStringifyInterceptor(value) {
317+
try {
318+
value = getValue(value);
319+
if (isDefined(value)) {
320+
value = stringify(value);
321+
}
322+
return value;
323+
} catch (err) {
324+
var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text,
325+
err.toString());
326+
$exceptionHandler(newErr);
327+
}
328+
}
311329
}
312330

313331

src/ng/parse.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -1253,13 +1253,22 @@ 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+
var result = interceptorFn(value, scope, locals);
1265+
return result;
1266+
} : function oneTimeInterceptedExpression(scope, locals) {
12581267
var value = parsedExpression(scope, locals);
12591268
var result = interceptorFn(value, scope, locals);
12601269
// we only return the interceptor's result if the
12611270
// initial value is defined (for bind-once)
1262-
return isDefined(value) || interceptorFn.$stateful ? result : value;
1271+
return isDefined(value) ? result : value;
12631272
};
12641273

12651274
// Propagate $$watchDelegates other then inputsWatchDelegate

0 commit comments

Comments
 (0)