Search WIP

This commit is contained in:
2023-02-27 08:41:19 +01:00
parent 64d7634b1b
commit a01c3a69b4
16 changed files with 128 additions and 100 deletions

View File

@@ -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)

View File

@@ -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; }
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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