using DynamicData; using DynamicData.Binding; using StabilityMatrix.Core.Services; namespace StabilityMatrix.Core.Models; public class IndexCollection where TKey : notnull { private readonly IImageIndexService imageIndexService; public string? RelativePath { get; set; } public SourceCache ItemsSource { get; } /// /// Observable Collection of indexed items /// public IObservableCollection Items { get; } = new ObservableCollectionExtended(); public IndexCollection( IImageIndexService imageIndexService, Func keySelector, Func< IObservable>, IObservable> >? transform = null ) { this.imageIndexService = imageIndexService; ItemsSource = new SourceCache(keySelector); var source = ItemsSource.Connect().DeferUntilLoaded(); if (transform is not null) { source = transform(source); } source.Bind(Items).Subscribe(); } public void Add(TObject item) { ItemsSource.AddOrUpdate(item); } public void Remove(TObject item) { ItemsSource.Remove(item); } public void RemoveKey(TKey key) { ItemsSource.RemoveKey(key); } }