ItemsCollection on Container

This commit is contained in:
2023-02-27 09:00:30 +01:00
parent a01c3a69b4
commit ffbd7b154c
11 changed files with 26 additions and 103 deletions

View File

@@ -1,3 +1,4 @@
using System.Collections.ObjectModel;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using DynamicData;
@@ -26,11 +27,19 @@ public record Container(
ReadOnlyExtensionCollection Extensions,
IObservable<IChangeSet<AbsolutePath, string>> Items) : IContainer
{
private readonly Lazy<ReadOnlyObservableCollection<AbsolutePath>> _itemsCollectionLazy =
new (() =>
{
Items.Bind(out var items).Subscribe();
return items;
});
private readonly CancellationTokenSource _loadingCancellationTokenSource = new();
public CancellationToken LoadingCancellationToken => _loadingCancellationTokenSource.Token;
public BehaviorSubject<bool> IsLoading { get; } = new(false);
IObservable<bool> IContainer.IsLoading => IsLoading.AsObservable();
public AbsolutePathType Type => AbsolutePathType.Container;
public ReadOnlyObservableCollection<AbsolutePath> ItemsCollection => _itemsCollectionLazy.Value;
public void CancelLoading() => _loadingCancellationTokenSource.Cancel();
}