Skip to content
This repository has been archived by the owner on Sep 5, 2024. It is now read-only.

fix($mdUtil) nextTick now keeps reference to correct scope. #8371

Closed
wants to merge 3 commits into from
Closed

fix($mdUtil) nextTick now keeps reference to correct scope. #8371

wants to merge 3 commits into from

Conversation

mgilson
Copy link
Contributor

@mgilson mgilson commented May 7, 2016

Previously, nextTick would decide whether to run the functions based
on the first scope argument passed during a given digest cycle. This
could fail in multiple scenarios ...

  1. The first nextTick call didn't supply a scope, but subsequent calls did.
  2. Multiple components (with different scopes) registered callbacks during the same digest cycle.

This could lead to callbacks being executed when they shouldn't be (if
the first scope registered wasn't $$destroyed, this this scope was),
or callbacks not being executed when they should be (the first scope was
$$destroyed, but this scope wasn't).

I believe that this fixes #8358

Matthew Lee Gilson added 2 commits May 6, 2016 15:11
Previously, `nextTick` would decide whether to run the functions based
on the first `scope` argument passed during a given digest cycle.  This
could fail in multiple scenarios ...

1) The first `nextTick` call didn't supply a scope, but subsequent calls did.
2) Multiple components (with different scopes) registered callbacks during the same digest cycle.

This could lead to callbacks being executed when they shouldn't be (if
the first scope registered wasn't $$destroyed, this _this_ scope was),
or callbacks not being executed when they should be (the first scope was
$$destroyed, but this scope wasn't).

I believe that this fixes #8358
@mgilson
Copy link
Contributor Author

mgilson commented May 7, 2016

I don't know how you guys feel about tiny cosmetic fixups being incorporated with a real change... If you'd rather, I can drop 0ea79f2 from this PR and submit it in a later PR (or not).

@mgilson mgilson changed the title nextTick now keeps reference to correct scope. fix($mdUtil) nextTick now keeps reference to correct scope. May 7, 2016
@@ -443,6 +443,22 @@ describe('util', function() {
flush(function(){ expect( callBackUsed ).toBeUndefined(); });
}));

it('should only skip callbacks of scopes which were destroyed', inject(function($mdUtil) {
var callBackUsed1, callback1 = function(){ callBackUsed1 = true};
Copy link
Contributor Author

Choose a reason for hiding this comment

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

FWIW, I like the way the callbacks are tracked via a jasmine spy (see line 232), but I used the same idiom used in the previous test since these tests are related. I'm happy to update both tests to use the spy idiom if you'd like.

* Moved `nextTick` tests all into the `describe('nextTick', ...` block
* Minor whitespace changes for consistency with what I've seen in the rest of the project
* used jasmine spys for call tracking since it is cleaner
@ThomasBurleson ThomasBurleson added the pr: merge ready This PR is ready for a caretaker to review label May 15, 2016
@ThomasBurleson ThomasBurleson added this to the 1.1.0 milestone May 15, 2016
@ThomasBurleson ThomasBurleson self-assigned this May 15, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr: merge ready This PR is ready for a caretaker to review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

md-autocomplete freezes UI when removed while loading items.
3 participants