Search WIP
This commit is contained in:
@@ -8,8 +8,10 @@ public static class DynamicDataExtensions
|
||||
{
|
||||
private class DisposableContext<TParam, TTaskResult>
|
||||
{
|
||||
private readonly SemaphoreSlim _semaphore = new(1, 1);
|
||||
private readonly Func<TParam, TTaskResult> _transformResult;
|
||||
private readonly TaskCompletionSource<TTaskResult?> _taskCompletionSource;
|
||||
private bool _isFinished;
|
||||
public IDisposable? Disposable { get; set; }
|
||||
|
||||
public DisposableContext(Func<TParam, TTaskResult> transformResult,
|
||||
@@ -22,6 +24,7 @@ public static class DynamicDataExtensions
|
||||
|
||||
public void OnNext(TParam param)
|
||||
{
|
||||
if (IsFinished()) return;
|
||||
Disposable?.Dispose();
|
||||
var result = _transformResult(param);
|
||||
_taskCompletionSource.SetResult(result);
|
||||
@@ -29,15 +32,27 @@ public static class DynamicDataExtensions
|
||||
|
||||
public void OnError(Exception ex)
|
||||
{
|
||||
if (IsFinished()) return;
|
||||
Disposable?.Dispose();
|
||||
_taskCompletionSource.SetException(ex);
|
||||
}
|
||||
|
||||
public void OnCompleted()
|
||||
{
|
||||
if (IsFinished()) return;
|
||||
Disposable?.Dispose();
|
||||
_taskCompletionSource.SetResult(default);
|
||||
}
|
||||
|
||||
private bool IsFinished()
|
||||
{
|
||||
_semaphore.Wait();
|
||||
var finished = _isFinished;
|
||||
_isFinished = true;
|
||||
_semaphore.Release();
|
||||
|
||||
return finished;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<IEnumerable<AbsolutePath>?> GetItemsAsync(
|
||||
@@ -46,12 +61,12 @@ public static class DynamicDataExtensions
|
||||
.Select(s =>
|
||||
s is null
|
||||
? new SourceList<AbsolutePath>().Connect().StartWithEmpty().ToCollection()
|
||||
: s.ToCollection())
|
||||
: s.StartWithEmpty().ToCollection())
|
||||
.Switch());
|
||||
|
||||
public static async Task<IEnumerable<AbsolutePath>?> GetItemsAsync(
|
||||
this IObservable<IChangeSet<AbsolutePath, string>> stream)
|
||||
=> await GetItemsAsync(stream.ToCollection());
|
||||
=> await GetItemsAsync(stream.StartWithEmpty().ToCollection());
|
||||
|
||||
public static Task<IEnumerable<AbsolutePath>?> GetItemsAsync(
|
||||
this IObservable<IReadOnlyCollection<AbsolutePath>> stream)
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace FileTime.Core.Models;
|
||||
|
||||
public interface IContainer : IItem
|
||||
{
|
||||
IObservable<IObservable<IChangeSet<AbsolutePath, string>>?> Items { get; }
|
||||
IObservable<IChangeSet<AbsolutePath, string>> Items { get; }
|
||||
IObservable<bool> IsLoading { get; }
|
||||
bool AllowRecursiveDeletion { get; }
|
||||
}
|
||||
@@ -10,11 +10,12 @@ namespace FileTime.Core.ContentAccess;
|
||||
public abstract class ContentProviderBase : IContentProvider
|
||||
{
|
||||
private readonly ReadOnlyExtensionCollection _extensions;
|
||||
private readonly IObservable<IChangeSet<AbsolutePath, string>> _items;
|
||||
|
||||
protected BehaviorSubject<IObservable<IChangeSet<AbsolutePath, string>>?> Items { get; } = new(null);
|
||||
protected SourceCache<AbsolutePath, string> Items { get; } = new(p => p.Path.Path);
|
||||
protected ExtensionCollection Extensions { get; }
|
||||
|
||||
IObservable<IObservable<IChangeSet<AbsolutePath, string>>?> IContainer.Items => Items;
|
||||
IObservable<IChangeSet<AbsolutePath, string>> IContainer.Items => _items;
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
@@ -59,6 +60,7 @@ public abstract class ContentProviderBase : IContentProvider
|
||||
FullName = FullName.CreateSafe(name);
|
||||
Extensions = new ExtensionCollection();
|
||||
_extensions = Extensions.AsReadOnly();
|
||||
_items = Items.Connect().StartWithEmpty();
|
||||
}
|
||||
|
||||
public virtual Task OnEnter() => Task.CompletedTask;
|
||||
|
||||
@@ -24,7 +24,7 @@ public record Container(
|
||||
PointInTime PointInTime,
|
||||
IObservable<IChangeSet<Exception>> Exceptions,
|
||||
ReadOnlyExtensionCollection Extensions,
|
||||
IObservable<IObservable<IChangeSet<AbsolutePath, string>>?> Items) : IContainer
|
||||
IObservable<IChangeSet<AbsolutePath, string>> Items) : IContainer
|
||||
{
|
||||
private readonly CancellationTokenSource _loadingCancellationTokenSource = new();
|
||||
public CancellationToken LoadingCancellationToken => _loadingCancellationTokenSource.Token;
|
||||
|
||||
@@ -52,8 +52,7 @@ public class Tab : ITab
|
||||
CurrentLocation
|
||||
.Where(c => c is not null)
|
||||
.Select(c => c!.Items)
|
||||
.Switch()
|
||||
.Select(items => items?.TransformAsync(MapItem)),
|
||||
.Select(items => items.TransformAsync(MapItem)),
|
||||
_itemFilters.Connect().StartWithEmpty().ToCollection(),
|
||||
(items, filters) =>
|
||||
items
|
||||
|
||||
Reference in New Issue
Block a user