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

test($rootScope): add tests clarifying $watchGroup oldValues behavior #16494

Merged
merged 1 commit into from
Apr 3, 2018

Conversation

jbedard
Copy link
Collaborator

@jbedard jbedard commented Mar 18, 2018

Closes #16024

The first group seem related but have always passed. The second group fail in v1.6.x as noted in the comments. IMO these tests (with the notes about 1.6) show how weird the oldValues were before.

Still need to add the BREAKING CHANGE message.

@jbedard jbedard force-pushed the 16024 branch 2 times, most recently from 87c5785 to 96dcafe Compare March 19, 2018 06:32
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.

LGTM except that:

  1. You need to have a : after BREAKING CHANGE in the commit message (per guidelines) 😁
  2. The breaking change notice doesn't make it clear that it refers to $watchGroup().
  3. Since this is a test(...) commit, it won't be included in the changelog (so we still need to manually include the BC, I think).

@jbedard jbedard force-pushed the 16024 branch 2 times, most recently from aebf6b0 to a8ddb03 Compare March 28, 2018 03:41
@jbedard
Copy link
Collaborator Author

jbedard commented Mar 28, 2018

I've updated the commit message and removed the extra comments from the tests.

@jbedard
Copy link
Collaborator Author

jbedard commented Mar 28, 2018

Also created #16514 for updating the changelog like we discussed

@jbedard
Copy link
Collaborator Author

jbedard commented Mar 29, 2018

Is the BC message 100% clear? There must be at least one typo in there! 😆

@gkalpak
Copy link
Member

gkalpak commented Mar 29, 2018

Is the BC message 100% clear?

It is to me.

There must be at least one typo in there!

Well...if you absolutely want to fix a typo, you can fix "will will lways" 😁

@jbedard
Copy link
Collaborator Author

jbedard commented Mar 29, 2018

Will fix that. Now I know you read it! 😄

@jbedard
Copy link
Collaborator Author

jbedard commented Mar 30, 2018

Fixed the typo in the commit message.

Closes angular#16024

BREAKING CHANGE:

(caused by c2b8fab)

Previously when using `$watchGroup` the entries in `newValues` and
`oldValues` represented the *most recent change of each entry*.

Now the entries in `oldValues` will always equal the `newValues` of the previous
call of the listener. This means comparing the entries in `newValues` and
`oldValues` can be used to determine which individual expressions changed.

For example `$scope.$watchGroup(['a', 'b'], fn)` would previously:

|  Action  |  newValue  |  oldValue  |
|----------|------------|------------|
|  (init)  | [undefined, undefined] | [undefined, undefined] |
|  `a=1`   | [1, undefined] | [undefined, undefined] |
|  `a=2`   | [2, undefined] | [1, undefined] |
|  `b=3`   | [2, 3] | [1, undefined] |

Now the `oldValue` will always equal the previous `newValue`:

|  Action  |  newValue  |  oldValue  |
|----------|------------|------------|
|  (init)  | [undefined, undefined] | [undefined, undefined] |
|  `a=1`   | [1, undefined] | [undefined, undefined] |
|  `a=2`   | [2, undefined] | [1, undefined] |
|  `b=3`   | [2, 3] | [2, undefined] |

Note the last call now shows `a === 2` in the `oldValues` array.

This also makes the `oldValue` of one-time watchers more clear. Previously
the `oldValue` of a one-time watcher would remain `undefined` forever. For
example `$scope.$watchGroup(['a', '::b'], fn)` would previously:

|  Action  |  newValue  |  oldValue  |
|----------|------------|------------|
|  (init)  | [undefined, undefined] | [undefined, undefined] |
|  `a=1`   | [1, undefined] | [undefined, undefined] |
|  `b=2`   | [1, 2] | [undefined, undefined] |
|  `a=b=3` | [3, 2] | [1, undefined] |

Where now the `oldValue` will always equal the previous `newValue`:

|  Action  |  newValue  |  oldValue  |
|----------|------------|------------|
|  (init)  | [undefined, undefined] | [undefined, undefined] |
|  `a=1`   | [1, undefined] | [undefined, undefined] |
|  `b=2`   | [1, 2] | [1, undefined] |
|  `a=b=3` | [3, 2] | [1, 2] |
@Narretz Narretz merged commit 4492db3 into angular:master Apr 3, 2018
@Narretz
Copy link
Contributor

Narretz commented Apr 3, 2018

I've merged the commit without the BC message. In a test scope commit it's just confusing.

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

Successfully merging this pull request may close these issues.

4 participants