Skip to content

Commit

Permalink
fix: Refactor collection change notifications and sorting
Browse files Browse the repository at this point in the history
Refactor `OnCollectionChanged` in `ExtendedObservableCollection.cs` to use `NotifyCollectionChangedAction.Reset` for simplification. Update `SortableObservableCollection.cs` to avoid sorting on `NotifyCollectionChangedAction.Reset` and add a check to sort only if the collection has at least two items.
  • Loading branch information
Stéphane ANDRE (E104915) committed Oct 9, 2024
1 parent 286ee21 commit 5ef22ff
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public IDisposable SuspendNotifications()
_suspendCount = false;
_suspendNotifications = false;
OnPropertyChanged(new PropertyChangedEventArgs("Count"));
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, Array.Empty<T>()));
OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}).Defer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,15 @@ protected override void InvokeNotifyCollectionChanged(NotifyCollectionChangedEve
{
base.InvokeNotifyCollectionChanged(notifyEventHandler, e);

if (SortSelector is null
|| e.Action == NotifyCollectionChangedAction.Remove
|| e.Action == NotifyCollectionChangedAction.Reset)
if (SortSelector is null || e.Action == NotifyCollectionChangedAction.Remove)
return;

Sort();
}

public void Sort()
{
if (SortSelector is null) return;
if (SortSelector is null || Count < 2) return;

ExecuteThreadSafe(() =>
{
Expand Down

0 comments on commit 5ef22ff

Please sign in to comment.