Skip to content

Commit 0c3ea3c

Browse files
committed
refactor($parse): separate one-time/normal interceptorFn logic
1 parent 8452a54 commit 0c3ea3c

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/ng/parse.js

+14-7
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,7 @@ function $ParseProvider() {
10951095
//oneTime is not part of the exp passed to the Parser so we may have to
10961096
//wrap the parsedExpression before adding a $$watchDelegate
10971097
parsedExpression = wrapSharedExpression(parsedExpression);
1098+
parsedExpression.oneTime = true;
10981099
parsedExpression.$$watchDelegate = parsedExpression.literal ?
10991100
oneTimeLiteralWatchDelegate : oneTimeWatchDelegate;
11001101
} else if (parsedExpression.inputs) {
@@ -1254,13 +1255,19 @@ function $ParseProvider() {
12541255
function addInterceptor(parsedExpression, interceptorFn) {
12551256
if (!interceptorFn) return parsedExpression;
12561257

1257-
var fn = function interceptedExpression(scope, locals) {
1258-
var value = parsedExpression(scope, locals);
1259-
var result = interceptorFn(value, scope, locals);
1260-
// we only return the interceptor's result if the
1261-
// initial value is defined (for bind-once)
1262-
return isDefined(value) || interceptorFn.$stateful ? result : value;
1263-
};
1258+
var fn;
1259+
if (parsedExpression.oneTime) {
1260+
fn = function interceptedOneTimeExpression(scope, locals) {
1261+
var value = parsedExpression(scope, locals);
1262+
if (isDefined(value)) {
1263+
return interceptorFn(value, scope, locals);
1264+
}
1265+
};
1266+
} else {
1267+
fn = function interceptedExpression(scope, locals) {
1268+
return interceptorFn(parsedExpression(scope, locals), scope, locals);
1269+
};
1270+
}
12641271

12651272
// Propagate $$watchDelegates other then inputsWatchDelegate
12661273
if (parsedExpression.$$watchDelegate &&

0 commit comments

Comments
 (0)