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

fix($rootScope): provide correct value of one-time bindings in watchGroup #15854

Merged
merged 1 commit into from
Mar 31, 2017

Conversation

jbedard
Copy link
Collaborator

@jbedard jbedard commented Mar 23, 2017

I don't recall how or why I came across this issue, and it's confusing me, but I found this stashed and the tests do make sense...?

@@ -1097,6 +1097,94 @@ describe('Scope', function() {
expect(log).toEqual('');
});

it('should remove all watchers once one-time/constant bindings are stable', function() {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This seems unrelated, but there are no other watcher-count tests so I thought I'd leave it in...

Copy link
Contributor

@Narretz Narretz left a comment

Choose a reason for hiding this comment

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

This looks useful. I wonder if there are performance implications with the new try ... catch block? I vaguely remember an issue where a try / catch block was not correctly optimized in V8, I think.
But I assume it's not performance critical as it is in the watchGroupAction fn

}));
});

describe('$watchGroup'/*with logging $exceptionHandler*/, function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is part of this commented out?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

idk, I guess I thought it was too long. I'll uncomment it...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated

@jbedard
Copy link
Collaborator Author

jbedard commented Mar 27, 2017

The try/catch only wraps the listener, not anything invoked per digest, so I wouldn't be too worried about it. The method is also quite simply and mainly just calls another method, so if that one method isn't optimized I don't think it's a big deal.

Copy link
Contributor

@Narretz Narretz left a comment

Choose a reason for hiding this comment

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

Ok, LGTM then. Needs one other review.

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.

A couple of minor clean-up comments.
LGTM otherwise.

listener(newValues, newValues, self);
} else {
listener(newValues, oldValues, self);
try {
Copy link
Member

Choose a reason for hiding this comment

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

FWIW, we could avoid the try/finally block, by using one extra array. But my intuition is that it won't make any difference.

expect(scope.$$watchersCount).toBe(0);
});

it('should maintain correct new/old values with one time bindings', inject(function($rootScope, $exceptionHandler) {
Copy link
Member

Choose a reason for hiding this comment

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

$exceptionHandler is not used. And you could probably use scope instead of $rootScope to avoid inject() altogether.

$exceptionHandlerProvider.mode('log');
});

inject(function($rootScope, $exceptionHandler) {
Copy link
Member

Choose a reason for hiding this comment

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

Consider using scope instead of $rootScope for consistency 😁

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've done this in the other tests which already have a beforeEach that sets scope, but this describe block is new... worth adding a beforeEach when there's only one test?

@jbedard
Copy link
Collaborator Author

jbedard commented Mar 29, 2017

Updated the tests. Will merge later today...

@jbedard jbedard merged commit c2b8fab into angular:master Mar 31, 2017
Narretz added a commit that referenced this pull request Jun 29, 2017
This should help to prevent issues such as #8671, #12452, #16004.

Note that the behavior will change in 1.7 (see #15854)

Closes #12643
Closes #16005
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.

4 participants