-
Notifications
You must be signed in to change notification settings - Fork 27.4k
refactor($rootScope): asyncQueue is pre-$parsed, no need to call $eval #15682
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One little thing. LGTM otherwise.
src/ng/rootScope.js
Outdated
// lead to a '$digest already in progress' error. | ||
for (var asyncQueuePosition = 0; asyncQueuePosition < asyncQueue.length; asyncQueuePosition++) { | ||
try { | ||
asyncTask = asyncQueue[asyncQueuePosition]; | ||
asyncTask.scope.$eval(asyncTask.expression, asyncTask.locals); | ||
asyncTask.expression(asyncTask.scope, asyncTask.locals); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this affect the this
inside expression?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you mean string expressions like 'this.foo'
, no, it won't affect them:
angular.injector(['ng']).get('$parse')('this.foo').call({foo: 1}, {foo: 2}); // 2
If you mean functions passed as expressions to $evalAsync
, it will affect them, but does this matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mean functions. I think it does (matter). For example, having a function that incorrectly tries to access this.someProp
, would previously throw (because this === undefined
), but will now silently fail.
I would rather not have the current behavior changed. (I mean would not change "this being undefined" - skipping the extra parsing (even if a no-op) lgtm.)
adf5752
to
6393d6a
Compare
@gkalpak ping |
// lead to a '$digest already in progress' error. | ||
for (var asyncQueuePosition = 0; asyncQueuePosition < asyncQueue.length; asyncQueuePosition++) { | ||
try { | ||
asyncTask = asyncQueue[asyncQueuePosition]; | ||
asyncTask.scope.$eval(asyncTask.expression, asyncTask.locals); | ||
fn = asyncTask.fn; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @jbedard correctly pointed out, it is a good idea to have some test about the context (or lack thereof), to guard against future "optimizations".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
minor refactoring
Does this PR introduce a breaking change?
no