Repository navigation
Commit 76926d8
authored
fix(reactiverecord): keep notification state out of derived record ToString and equality (#4482)
## Summary
**Records that derive from `ReactiveRecord` print and compare only their
own members.**
- **`ToString()` no longer lists `Changing`, `Changed` and
`ThrownExceptions`.** A derived record prints `CourseResult {
StudentName = Ada, Score = 90 }`, the usual record output.
- **Value equality and `GetHashCode()` ignore the base record's
notification state.** Two records with equal members stay equal after
either one is printed, observed or subscribed to.
## Why
**The compiler-generated record members covered `ReactiveRecord`'s own
properties and fields.**
- `ToString()` printed the internal observable type names ahead of the
record's data.
- `Equals` and `GetHashCode` compared the lazily created observables,
event handlers and subscription flags. Fresh records compared equal,
then stopped being equal once one of them was used, so a record could
get lost in a `HashSet<T>` or dictionary.
Closes #4476
Closes #4477
## Breaking changes
**Behaviour change: derived records now always use value equality over
their own members.**
- Code that relied on two such records comparing unequal after one had
been observed now sees them as equal, which is what record equality
promises.
## How this was verified
**Tests cover the printed output, equality and hash code after the
observables are read and handlers are added, and inequality for
different members.**
## Notes for the reviewer
**The whole change is three members in `ReactiveRecord.cs`.**
- `PrintMembers` returns `false`, and `Equals(ReactiveRecord?)` /
`GetHashCode()` use only `EqualityContract`, so each derived record's
synthesized code handles its own members.
- The file is shared source, so `ReactiveUI.Reactive` gets the same fix.
## Checklist
- [x] I have read the [Contribute
guide](https://www.reactiveui.net/contribute/index.html)
- [x] The PR title follows [Conventional
Commits](https://www.conventionalcommits.org/)
- [x] Tests cover this change, or the summary says why they do not
- [x] New or changed public API has XML documentation1 parent 1fcd23c commit 76926d8
2 files changed
Lines changed: 64 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
108 | 121 | | |
109 | 122 | | |
110 | 123 | | |
111 | 124 | | |
112 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
113 | 131 | | |
114 | 132 | | |
115 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
289 | 335 | | |
290 | 336 | | |
291 | 337 | | |
| |||
0 commit comments