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

refactor($rootScope): asyncQueue is pre-$parsed, no need to call $eval #15682

Closed
wants to merge 1 commit into from

Conversation

thorn0
Copy link
Contributor

@thorn0 thorn0 commented Feb 6, 2017

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

minor refactoring

Does this PR introduce a breaking change?

no

Copy link
Member

@gkalpak gkalpak left a 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.

// 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);
Copy link
Member

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?

Copy link
Contributor Author

@thorn0 thorn0 Feb 7, 2017

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?

Copy link
Member

@gkalpak gkalpak Feb 7, 2017

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

@gkalpak gkalpak added this to the Backlog milestone Feb 7, 2017
@thorn0 thorn0 force-pushed the asyncQueue branch 2 times, most recently from adf5752 to 6393d6a Compare February 8, 2017 07:16
@thorn0
Copy link
Contributor Author

thorn0 commented Feb 8, 2017

@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;
Copy link
Member

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants