Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3907086

Browse files
committedNov 11, 2014
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 3907086

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed
 

‎src/ng/interpolate.js

+7-5
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('');
@@ -231,8 +231,10 @@ function $InterpolateProvider() {
231231
if (!mustHaveExpression || expressions.length) {
232232
var compute = function(values) {
233233
for (var i = 0, ii = expressions.length; i < ii; i++) {
234-
if (allOrNothing && isUndefined(values[i])) return;
235-
concat[expressionPositions[i]] = values[i];
234+
if (allOrNothing && isUndefined(values[i])) {
235+
return;
236+
}
237+
concat[expressionPositions[i]] = parseStringifyValue(values[i]);
236238
}
237239
return concat.join('');
238240
};
@@ -299,12 +301,12 @@ function $InterpolateProvider() {
299301
replace(escapedEndRegexp, endSymbol);
300302
}
301303

302-
function parseStringifyInterceptor(value) {
304+
function parseStringifyValue(value) {
303305
try {
304306
return stringify(getValue(value));
305307
} catch (err) {
306308
var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text,
307-
err.toString());
309+
err.toString());
308310
$exceptionHandler(newErr);
309311
}
310312
}

‎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)