Skip to content

Commit b062fb3

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 b062fb3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/ng/interpolate.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ function $InterpolateProvider() {
202202
}
203203
exp = text.substring(startIndex + startSymbolLength, endIndex);
204204
expressions.push(exp);
205-
parseFns.push($parse(exp, parseStringifyInterceptor));
205+
parseFns.push($parse(exp));
206206
index = endIndex + endSymbolLength;
207207
expressionPositions.push(concat.length);
208208
concat.push('');
@@ -232,7 +232,7 @@ function $InterpolateProvider() {
232232
var compute = function(values) {
233233
for (var i = 0, ii = expressions.length; i < ii; i++) {
234234
if (allOrNothing && isUndefined(values[i])) return;
235-
concat[expressionPositions[i]] = values[i];
235+
concat[expressionPositions[i]] = parseStringifyValue(values[i]);
236236
}
237237
return concat.join('');
238238
};
@@ -299,7 +299,7 @@ function $InterpolateProvider() {
299299
replace(escapedEndRegexp, endSymbol);
300300
}
301301

302-
function parseStringifyInterceptor(value) {
302+
function parseStringifyValue(value) {
303303
try {
304304
return stringify(getValue(value));
305305
} catch (err) {

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)