Repository navigation
Fixed bogus lookup logic within list-land .TransformAsync(),…
#1171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
18b0f53
f13952f
403d0ec
06d2dbe
35551ba
1dc7af0
c341cfa
101fb75
deddae5
4d81cb1
cd3a996
387fc12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,16 +134,24 @@ await _containerFactory( | |
| case ListChangeReason.Refresh: | ||
| { | ||
| var change = item.Item; | ||
| var index = change.CurrentIndex; | ||
|
|
||
| if (index < 0) | ||
| { | ||
| index = transformed.FindItemIndex(change.Current); | ||
| if (index < 0) | ||
| break; | ||
| } | ||
|
|
||
| if (_transformOnRefresh) | ||
| { | ||
| Optional<TDestination> previous = transformed[change.CurrentIndex].Destination; | ||
| var container = await _containerFactory(change.Current, previous, change.CurrentIndex, cancel) | ||
| var container = await _containerFactory(change.Current, transformed[index].Destination, index, cancel) | ||
| .ConfigureAwait(false); | ||
| transformed[change.CurrentIndex] = container; | ||
| transformed[index] = container; | ||
| } | ||
| else | ||
| { | ||
| transformed.RefreshAt(change.CurrentIndex); | ||
| transformed.RefreshAt(index); | ||
| } | ||
|
|
||
| break; | ||
|
|
@@ -152,16 +160,23 @@ await _containerFactory( | |
| case ListChangeReason.Replace: | ||
| { | ||
| var change = item.Item; | ||
| var currentIndex = change.CurrentIndex; | ||
| var previousIndex = change.PreviousIndex; | ||
|
|
||
| if (previousIndex < 0) | ||
| previousIndex = transformed.FindItemIndex(change.Previous.Value); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the previous item isn't found, this falls through to
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per my initial comment, I left in all the existing discrepancies in failed lookup behavior intact. They're not part of #1169, and and how an operator responds to being given corrupt changesets is really undefined behavior. I'm down with cleaning it up, but not here. |
||
|
|
||
| Optional<TDestination> previous = transformed[change.PreviousIndex].Destination; | ||
| if (change.CurrentIndex == change.PreviousIndex) | ||
| if (currentIndex < 0) | ||
| currentIndex = previousIndex; | ||
|
|
||
| if (currentIndex == previousIndex) | ||
| { | ||
| transformed[change.CurrentIndex] = await _containerFactory(change.Current, previous, change.CurrentIndex, cancel); | ||
| transformed[currentIndex] = await _containerFactory(change.Current, transformed[previousIndex].Destination, currentIndex, cancel); | ||
| } | ||
| else | ||
| { | ||
| transformed.RemoveAt(change.PreviousIndex); | ||
| transformed.Insert(change.CurrentIndex, await _containerFactory(change.Current, Optional<TDestination>.None, change.CurrentIndex, cancel)); | ||
| transformed.RemoveAt(previousIndex); | ||
| transformed.Insert(currentIndex, await _containerFactory(change.Current, Optional<TDestination>.None, currentIndex, cancel)); | ||
| } | ||
|
|
||
| break; | ||
|
|
@@ -170,22 +185,16 @@ await _containerFactory( | |
| case ListChangeReason.Remove: | ||
| { | ||
| var change = item.Item; | ||
| var hasIndex = change.CurrentIndex >= 0; | ||
| var index = change.CurrentIndex; | ||
|
|
||
| if (hasIndex) | ||
| if (index < 0) | ||
| { | ||
| transformed.RemoveAt(item.Item.CurrentIndex); | ||
| } | ||
| else | ||
| { | ||
| var toRemove = transformed.FirstOrDefault(t => ReferenceEquals(t.Source, t)); | ||
|
|
||
| if (toRemove is not null) | ||
| { | ||
| transformed.Remove(toRemove); | ||
| } | ||
| index = transformed.FindItemIndex(change.Current); | ||
| if (index < 0) | ||
| break; | ||
| } | ||
|
|
||
| transformed.RemoveAt(index); | ||
| break; | ||
| } | ||
|
|
||
|
|
@@ -197,8 +206,14 @@ await _containerFactory( | |
| } | ||
| else | ||
| { | ||
| var toRemove = transformed.Where(t => ReferenceEquals(t.Source, t)).ToArray(); | ||
| transformed.RemoveMany(toRemove); | ||
| foreach (var current in item.Range) | ||
| { | ||
| var index = transformed.FindItemIndex(current); | ||
| if (index < 0) | ||
| continue; | ||
|
|
||
| transformed.RemoveAt(index); | ||
| } | ||
| } | ||
|
|
||
| break; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add a duplicate-values case (e.g. [1,2,1,2] with an unindexed RemoveRange of [1,2]) and an unindexed Replace for both operators? The duplicates test would have caught the extra loop in the async version. Also, small thing: the
// Covers/// Mirrors coveragecomments and the trailing whitespace are still there.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just added some duplicate items to the existing tests. It's not like we lose any coverage by dropping the no-duplicates scenario.
Uhhh, yeah, why wouldn't they be? And what trailing whitespace?