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

fix(ngOptions): use watchCollection not deep watch of ngModel #11743

Closed
wants to merge 2 commits into from

Conversation

petebacondarwin
Copy link
Contributor

No description provided.

@lgalfaso
Copy link
Contributor

Tests comments, code comments and documentation need to be updated to reflect the change. Otherwise, LGTM

@petebacondarwin
Copy link
Contributor Author

@lgalfaso I added tests and docs. Can you review?

@gkalpak
Copy link
Member

gkalpak commented Apr 28, 2015

After a superficial look it lgtm, but I wonder if this qualifies as a breaking change.
I find it unlikely that someone was relying on having the view reflect a change in a deeper level of the selected item, but it a breaking change notice might be inplace (just in case).

I don't know why I am mentioning it; I probably shouldn't, but I just have to get it out (please ignore 😄):

// A few (insignificant) lines of (test) code can be saved and 
// readability can be marginally improved (imo), by replacing occurrences of:
scope.$apply(function() {
  scope.x = y;
});

// with:
scope.$apply('x = y');

@petebacondarwin
Copy link
Contributor Author

@gkalpak - yeah I know what you mean about the BC message. I was trying to get away without one. But I guess it doesn't do any harm to highlight this.

@gkalpak - yeah I know what you are saying about $apply expressions and I tend to fluctuate back and forth between the two styles. On one hand I want to be consistent and on the other concise. The former is tricky when there are occasions when you cannot express what you want to change on the scope in an Angular expression.

@petebacondarwin
Copy link
Contributor Author

In 1.3.15 it totally doesn't work if you update deeper properties on the model so this is not a breaking change, IMO

Compare 1.3.15: http://plnkr.co/edit/zsgnhflQ3M1ClUSrsne0?p=preview
to snapshot: http://plnkr.co/edit/hI48vBc0GscyYTYucJ0U?p=preview

Using a deep watch caused Angular to enter an infinite recursion in the
case that the model contains a circular reference.  Using `$watchCollection`
instead prevents this from happening.

This change means that we will not re-render the directive when there is
a change below the first level of properties on the model object. Making
such a change is a strange corner case that is unlikely to occur in practice
and the directive is not designed to support such a situation. The
documentation has been updated to clarify this behaviour.

This is not a breaking change since in 1.3.x this scenario did not work
at all. Compare 1.3.15: http://plnkr.co/edit/zsgnhflQ3M1ClUSrsne0?p=preview
to snapshot: http://plnkr.co/edit/hI48vBc0GscyYTYucJ0U?p=preview

Closes angular#11372
Closes angular#11653
Closes angular#11743
@gkalpak
Copy link
Member

gkalpak commented Apr 29, 2015

I was referring to a breaking change since 1.4.0-rc.1 (for people upgrading from that version to 1.4.0-rc.2 or later). But it's a minor one anyway.

@@ -901,8 +949,7 @@ describe('ngOptions', function() {

// Update the properties on the object in the selected array, rather than replacing the whole object
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment should be updated, and so the test description.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lgalfaso - looking at this a little more I am now thinking that in the specific situation of multiple + track by we should handle the value of the track by changing within each of the items in the collection of selected values.
I will put together an additional PR, which also should eliminate any form of BC to keep @gkalpak happy :-P

@lgalfaso
Copy link
Contributor

Just two small comments. Otherwise, LGTM

petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request May 1, 2015
Commit 47f9fc3 failed to account for changes to
the tracked value of model items in a collection where the select was `multiple`.

See angular#11743 (comment)
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request May 1, 2015
Commit 47f9fc3 failed to account for changes to
the tracked value of model items in a collection where the select was `multiple`.

See angular#11743 (comment)
petebacondarwin added a commit to petebacondarwin/angular.js that referenced this pull request May 1, 2015
Commit 47f9fc3 failed to account for changes to
the tracked value of model items in a collection where the select was `multiple`.

See angular#11743 (comment)
petebacondarwin added a commit that referenced this pull request May 5, 2015
Commit 47f9fc3 failed to account for changes to
the tracked value of model items in a collection where the select was `multiple`.

See #11743 (comment)

Closes #11784
netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
Using a deep watch caused Angular to enter an infinite recursion in the
case that the model contains a circular reference.  Using `$watchCollection`
instead prevents this from happening.

This change means that we will not re-render the directive when there is
a change below the first level of properties on the model object. Making
such a change is a strange corner case that is unlikely to occur in practice
and the directive is not designed to support such a situation. The
documentation has been updated to clarify this behaviour.

This is not a breaking change since in 1.3.x this scenario did not work
at all. Compare 1.3.15: http://plnkr.co/edit/zsgnhflQ3M1ClUSrsne0?p=preview
to snapshot: http://plnkr.co/edit/hI48vBc0GscyYTYucJ0U?p=preview

Closes angular#11372
Closes angular#11653
Closes angular#11743
netman92 pushed a commit to netman92/angular.js that referenced this pull request Aug 8, 2015
Commit 47f9fc3 failed to account for changes to
the tracked value of model items in a collection where the select was `multiple`.

See angular#11743 (comment)

Closes angular#11784
@petebacondarwin petebacondarwin deleted the fix11372 branch November 24, 2016 09:21
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.

None yet

4 participants