This repository was archived by the owner on Apr 12, 2024. It is now read-only.
Commit 8f13833
committed
test($rootScope): add tests clarifying $watchGroup oldValues behavior
Closes #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] |1 parent a8bef95 commit 8f13833
1 file changed
+109
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1462 | 1462 | | |
1463 | 1463 | | |
1464 | 1464 | | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
| 1481 | + | |
| 1482 | + | |
| 1483 | + | |
| 1484 | + | |
| 1485 | + | |
| 1486 | + | |
| 1487 | + | |
| 1488 | + | |
| 1489 | + | |
| 1490 | + | |
| 1491 | + | |
| 1492 | + | |
| 1493 | + | |
| 1494 | + | |
| 1495 | + | |
| 1496 | + | |
| 1497 | + | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
1465 | 1508 | | |
1466 | 1509 | | |
1467 | 1510 | | |
| |||
1542 | 1585 | | |
1543 | 1586 | | |
1544 | 1587 | | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 1612 | + | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
1545 | 1654 | | |
1546 | 1655 | | |
1547 | 1656 | | |
| |||
0 commit comments