Multi-Platform Package Manager for Stable Diffusion
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
1.4 KiB

using DynamicData;
using DynamicData.Binding;
using StabilityMatrix.Core.Services;
namespace StabilityMatrix.Core.Models;
public class IndexCollection<TObject, TKey>
where TKey : notnull
{
private readonly IImageIndexService imageIndexService;
public string? RelativePath { get; set; }
public SourceCache<TObject, TKey> ItemsSource { get; }
/// <summary>
/// Observable Collection of indexed items
/// </summary>
public IObservableCollection<TObject> Items { get; } =
new ObservableCollectionExtended<TObject>();
public IndexCollection(
IImageIndexService imageIndexService,
Func<TObject, TKey> keySelector,
Func<
IObservable<IChangeSet<TObject, TKey>>,
IObservable<IChangeSet<TObject, TKey>>
>? transform = null
)
{
this.imageIndexService = imageIndexService;
ItemsSource = new SourceCache<TObject, TKey>(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);
}
}