Fix more edge cases

This commit is contained in:
TheXamlGuy
2024-05-31 22:50:52 +01:00
parent 8f1a3252c6
commit c24538f545
16 changed files with 212 additions and 118 deletions
+15 -12
View File
@@ -192,20 +192,20 @@ public partial class ObservableCollection<TItem> :
}
}
public void BeginAggregation()
public void Fetch(bool reset = false)
{
if (this.GetAttribute<AggerateAttribute>() is AggerateAttribute attribute)
if (reset)
{
if (attribute.Mode == AggerateMode.Reset)
{
Clear();
}
object? key = this.GetPropertyValue(() => attribute.Key) is { } value ? value : attribute.Key;
Publisher.PublishUI(OnAggerate(key));
Clear();
}
AggregateExpression expression = CreateAggregateExpression();
Publisher.PublishUI(expression.Value, expression.Key);
}
protected virtual IAggregate OnAggerate() =>
new AggerateEventArgs<TItem>();
public void Clear()
{
clearing = true;
@@ -389,7 +389,7 @@ public partial class ObservableCollection<TItem> :
}
Initialized = true;
BeginAggregation();
Fetch();
return Task.CompletedTask;
}
@@ -565,8 +565,11 @@ public partial class ObservableCollection<TItem> :
collection.Insert(index > Count ? Count : index, item);
}
protected virtual IAggerate OnAggerate(object? key) =>
new AggerateEventArgs<TItem>() with { Key = key };
protected virtual AggregateExpression CreateAggregateExpression() =>
new AggregateExpression(new AggerateEventArgs<TItem>());
protected virtual object? CreateAggregationKey() =>
default;
protected virtual void RemoveItem(int index) =>
collection.RemoveAt(index);