Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

refactor($parse): don't use bind-once interceptor for non-bind-once expressions #9961

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/ng/interpolate.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ function $InterpolateProvider() {

function parseStringifyInterceptor(value) {
try {
return stringify(getValue(value));
value = getValue(value);
return allOrNothing && !isDefined(value) ? value : stringify(value);
} catch (err) {
var newErr = $interpolateMinErr('interr', "Can't interpolate: {0}\n{1}", text,
err.toString());
Expand Down
12 changes: 10 additions & 2 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -1253,13 +1253,21 @@ function $ParseProvider() {

function addInterceptor(parsedExpression, interceptorFn) {
if (!interceptorFn) return parsedExpression;
var watchDelegate = parsedExpression.$$watchDelegate;

var fn = function interceptedExpression(scope, locals) {
var regularWatch =
watchDelegate !== oneTimeLiteralWatchDelegate &&
watchDelegate !== oneTimeWatchDelegate;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am torn about this, on one side I do not like the idea that we behave different because we know that the interceptor is X or Y (tomorrow we are going to add a third interceptor and the list can keep on growing). On the other side I would like not to have to add some magic property (as we already have too much magic)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interceptors shouldn't exist in the first place, so let this be a motivation for getting rid of them :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto for watchDelegates, they are terrible

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that is another approach to fixing this that I think is worth looking into


var fn = regularWatch ? function regularInterceptedExpression(scope, locals) {
var value = parsedExpression(scope, locals);
return interceptorFn(value, scope, locals);
} : function oneTimeInterceptedExpression(scope, locals) {
var value = parsedExpression(scope, locals);
var result = interceptorFn(value, scope, locals);
// we only return the interceptor's result if the
// initial value is defined (for bind-once)
return isDefined(value) || interceptorFn.$stateful ? result : value;
return isDefined(value) ? result : value;
};

// Propagate $$watchDelegates other then inputsWatchDelegate
Expand Down