WIP
This commit is contained in:
@@ -1,10 +0,0 @@
|
|||||||
namespace Toolkit.Foundation;
|
|
||||||
|
|
||||||
public record Aggregate
|
|
||||||
{
|
|
||||||
public static AggerateEventArgs<TValue, TOptions> As<TValue, TOptions>(TOptions options)
|
|
||||||
where TOptions : class => new(options);
|
|
||||||
|
|
||||||
public static AggerateEventArgs<TValue> As<TValue>() =>
|
|
||||||
new();
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
namespace Toolkit.Foundation;
|
|
||||||
|
|
||||||
public record AggerateEventArgs<TType, TValue>(TValue? Value = default) :
|
|
||||||
IAggregate;
|
|
||||||
|
|
||||||
public record AggerateEventArgs<TType> :
|
|
||||||
IAggregate;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
namespace Toolkit.Foundation;
|
|
||||||
|
|
||||||
public record AggregateExpression(IAggregate Value, object? Key = null);
|
|
||||||
@@ -45,8 +45,6 @@ public class ComponentBuilder :
|
|||||||
|
|
||||||
services.AddHandler<NavigateHandler>();
|
services.AddHandler<NavigateHandler>();
|
||||||
services.AddHandler<NavigateBackHandler>();
|
services.AddHandler<NavigateBackHandler>();
|
||||||
|
|
||||||
services.AddTransient<ICollectionSynchronizer, CollectionSynchronizer>();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
public record Create
|
public record Create
|
||||||
{
|
{
|
||||||
public static CreateEventArgs<TValue> As<TValue>(TValue value) =>
|
public static CreateEventArgs<TValue> As<TValue>(TValue value, params object[] Parameters) =>
|
||||||
new(value);
|
new(value);
|
||||||
|
|
||||||
public static CreateEventArgs<TValue> As<TValue>() where TValue : new() =>
|
public static CreateEventArgs<TValue> As<TValue>(params object[] Parameters) where TValue : new() =>
|
||||||
new(new TValue());
|
new(new TValue());
|
||||||
}
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Toolkit.Foundation;
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
public record CreateEventArgs<TValue>(TValue Value);
|
public record CreateEventArgs<TValue>(TValue Value, params object[] Parameters);
|
||||||
@@ -65,8 +65,6 @@ public class DefaultHostBuilder :
|
|||||||
services.AddHandler<NavigateHandler>();
|
services.AddHandler<NavigateHandler>();
|
||||||
services.AddHandler<NavigateBackHandler>();
|
services.AddHandler<NavigateBackHandler>();
|
||||||
|
|
||||||
services.AddTransient<ICollectionSynchronizer, CollectionSynchronizer>();
|
|
||||||
|
|
||||||
services.AddInitializer<ComponentInitializer>();
|
services.AddInitializer<ComponentInitializer>();
|
||||||
services.AddHostedService<AppService>();
|
services.AddHostedService<AppService>();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
public class HandlerWrapper<TRequest, TResponse>(IHandler<TRequest, TResponse> handler,
|
public class HandlerWrapper<TRequest, TResponse>(IHandler<TRequest, TResponse> handler,
|
||||||
IEnumerable<IPipelineBehaviour<TRequest, TResponse>> pipelineBehaviours)
|
IEnumerable<IPipelineBehaviour<TRequest, TResponse>> pipelineBehaviours)
|
||||||
where TRequest : class
|
where TRequest : notnull
|
||||||
{
|
{
|
||||||
private readonly IEnumerable<IPipelineBehaviour<TRequest, TResponse>> pipelineBehaviours =
|
private readonly IEnumerable<IPipelineBehaviour<TRequest, TResponse>> pipelineBehaviours =
|
||||||
pipelineBehaviours.Reverse();
|
pipelineBehaviours.Reverse();
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public interface IIndexable
|
||||||
|
{
|
||||||
|
public int Index { get; }
|
||||||
|
}
|
||||||
@@ -106,8 +106,7 @@ public static class IServiceCollectionExtensions
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (key is not null)
|
if (key is not null)
|
||||||
{
|
{
|
||||||
|
|
||||||
services.Add(new ServiceDescriptor(wrapperType, key, (provider, key) =>
|
services.Add(new ServiceDescriptor(wrapperType, key, (provider, key) =>
|
||||||
provider.GetService<IServiceFactory>()?.Create(wrapperType,
|
provider.GetService<IServiceFactory>()?.Create(wrapperType,
|
||||||
provider.GetRequiredKeyedService<THandler>(key),
|
provider.GetRequiredKeyedService<THandler>(key),
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public interface ISynchronizationCollection<TItem>
|
||||||
|
{
|
||||||
|
int IndexOf(TItem item);
|
||||||
|
}
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
namespace Toolkit.Foundation;
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
public interface IAggregate;
|
public interface ISynchronize;
|
||||||
@@ -6,40 +6,6 @@ using System.Reactive.Disposables;
|
|||||||
|
|
||||||
namespace Toolkit.Foundation;
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
public interface IIndexable
|
|
||||||
{
|
|
||||||
int Index { get; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ICollectionSynchronization<TItem>
|
|
||||||
where TItem : notnull
|
|
||||||
{
|
|
||||||
int IndexOf(TItem item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface ICollectionSynchronizer
|
|
||||||
{
|
|
||||||
void Set<TItem>(ICollectionSynchronization<TItem> collection)
|
|
||||||
where TItem : notnull;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CollectionSynchronizer(IServiceProvider serviceProvider) :
|
|
||||||
ICollectionSynchronizer
|
|
||||||
{
|
|
||||||
private readonly IServiceProvider serviceProvider = serviceProvider;
|
|
||||||
|
|
||||||
public void Set<TItem>(ICollectionSynchronization<TItem> collection)
|
|
||||||
where TItem : notnull
|
|
||||||
{
|
|
||||||
if (serviceProvider.GetService<IDecoratorService<ICollectionSynchronization<TItem>>>()
|
|
||||||
is IDecoratorService<ICollectionSynchronization<TItem>> decoratorService)
|
|
||||||
{
|
|
||||||
decoratorService.Set(collection);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public partial class ObservableCollection<TItem> :
|
public partial class ObservableCollection<TItem> :
|
||||||
ObservableObject,
|
ObservableObject,
|
||||||
IObservableCollectionViewModel<TItem>,
|
IObservableCollectionViewModel<TItem>,
|
||||||
@@ -52,7 +18,7 @@ public partial class ObservableCollection<TItem> :
|
|||||||
IList,
|
IList,
|
||||||
IReadOnlyList<TItem>,
|
IReadOnlyList<TItem>,
|
||||||
INotifyCollectionChanged,
|
INotifyCollectionChanged,
|
||||||
ICollectionSynchronization<TItem>,
|
ISynchronizationCollection<TItem>,
|
||||||
IServiceProviderRequired,
|
IServiceProviderRequired,
|
||||||
IServiceFactoryRequired,
|
IServiceFactoryRequired,
|
||||||
IMediatorRequired,
|
IMediatorRequired,
|
||||||
@@ -89,16 +55,13 @@ public partial class ObservableCollection<TItem> :
|
|||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private TItem? selectedItem;
|
private TItem? selectedItem;
|
||||||
|
|
||||||
public ObservableCollection(ICollectionSynchronizer synchronizer,
|
public ObservableCollection(IServiceProvider provider,
|
||||||
IServiceProvider provider,
|
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer)
|
IDisposer disposer)
|
||||||
{
|
{
|
||||||
synchronizer.Set(this);
|
|
||||||
|
|
||||||
Provider = provider;
|
Provider = provider;
|
||||||
Factory = factory;
|
Factory = factory;
|
||||||
Mediator = mediator;
|
Mediator = mediator;
|
||||||
@@ -111,8 +74,7 @@ public partial class ObservableCollection<TItem> :
|
|||||||
collection.CollectionChanged += OnCollectionChanged;
|
collection.CollectionChanged += OnCollectionChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ObservableCollection(ICollectionSynchronizer synchronizer,
|
public ObservableCollection(IServiceProvider provider,
|
||||||
IServiceProvider provider,
|
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
@@ -120,8 +82,6 @@ public partial class ObservableCollection<TItem> :
|
|||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
IEnumerable<TItem> items)
|
IEnumerable<TItem> items)
|
||||||
{
|
{
|
||||||
synchronizer.Set(this);
|
|
||||||
|
|
||||||
Provider = provider;
|
Provider = provider;
|
||||||
Factory = factory;
|
Factory = factory;
|
||||||
Mediator = mediator;
|
Mediator = mediator;
|
||||||
@@ -139,6 +99,7 @@ public partial class ObservableCollection<TItem> :
|
|||||||
public event NotifyCollectionChangedEventHandler? CollectionChanged;
|
public event NotifyCollectionChangedEventHandler? CollectionChanged;
|
||||||
|
|
||||||
public event EventHandler? DeactivateHandler;
|
public event EventHandler? DeactivateHandler;
|
||||||
|
|
||||||
public IDisposer Disposer { get; private set; }
|
public IDisposer Disposer { get; private set; }
|
||||||
|
|
||||||
public IServiceFactory Factory { get; private set; }
|
public IServiceFactory Factory { get; private set; }
|
||||||
@@ -240,11 +201,11 @@ public partial class ObservableCollection<TItem> :
|
|||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
AggregateExpression expression = BuildAggregateExpression();
|
SynchronizeExpression expression = BuildAggregateExpression();
|
||||||
Publisher.PublishUI(expression.Value, expression.Key);
|
Publisher.PublishUI(expression.Value, expression.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Fetch(Func<AggregateExpression> aggregateDelegate,
|
public void Fetch(Func<SynchronizeExpression> aggregateDelegate,
|
||||||
bool reset = false)
|
bool reset = false)
|
||||||
{
|
{
|
||||||
if (reset)
|
if (reset)
|
||||||
@@ -252,7 +213,7 @@ public partial class ObservableCollection<TItem> :
|
|||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
AggregateExpression expression = aggregateDelegate.Invoke();
|
SynchronizeExpression expression = aggregateDelegate.Invoke();
|
||||||
Publisher.PublishUI(expression.Value, expression.Key);
|
Publisher.PublishUI(expression.Value, expression.Key);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -616,8 +577,8 @@ public partial class ObservableCollection<TItem> :
|
|||||||
collection.Insert(index > Count ? Count : index, item);
|
collection.Insert(index > Count ? Count : index, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual AggregateExpression BuildAggregateExpression() =>
|
protected virtual SynchronizeExpression BuildAggregateExpression() =>
|
||||||
new(new AggerateEventArgs<TItem>());
|
new(new SynchronizeEventArgs<TItem>());
|
||||||
|
|
||||||
protected virtual void RemoveItem(int index) =>
|
protected virtual void RemoveItem(int index) =>
|
||||||
collection.RemoveAt(index);
|
collection.RemoveAt(index);
|
||||||
@@ -664,12 +625,11 @@ public partial class ObservableCollection<TItem> :
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public partial class ObservableCollection<TValue, TViewModel>(ICollectionSynchronizer synchronizer,
|
public partial class ObservableCollection<TValue, TViewModel>(IServiceProvider provider,
|
||||||
IServiceProvider provider,
|
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber, IDisposer disposer) : ObservableCollection<TViewModel>(synchronizer, provider, factory, mediator, publisher, subscriber, disposer)
|
ISubscription subscriber, IDisposer disposer) : ObservableCollection<TViewModel>(provider, factory, mediator, publisher, subscriber, disposer)
|
||||||
where TViewModel : notnull,
|
where TViewModel : notnull,
|
||||||
IDisposable
|
IDisposable
|
||||||
{
|
{
|
||||||
@@ -677,11 +637,10 @@ public partial class ObservableCollection<TValue, TViewModel>(ICollectionSynchro
|
|||||||
private TValue? value;
|
private TValue? value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ObservableCollection(ICollectionSynchronizer synchronizer,
|
public class ObservableCollection(IServiceProvider provider,
|
||||||
IServiceProvider provider,
|
|
||||||
IServiceFactory factory,
|
IServiceFactory factory,
|
||||||
IMediator mediator,
|
IMediator mediator,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscription subscriber,
|
ISubscription subscriber,
|
||||||
IDisposer disposer) :
|
IDisposer disposer) :
|
||||||
ObservableCollection<IDisposable>(synchronizer, provider, factory, mediator, publisher, subscriber, disposer);
|
ObservableCollection<IDisposable>(provider, factory, mediator, publisher, subscriber, disposer);
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public record Synchronize
|
||||||
|
{
|
||||||
|
public static SynchronizeEventArgs<TValue, TOptions> As<TValue, TOptions>(TOptions options)
|
||||||
|
where TOptions : class => new(options);
|
||||||
|
|
||||||
|
public static SynchronizeEventArgs<TValue> As<TValue>() =>
|
||||||
|
new();
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public record SynchronizeEventArgs<TSynchronize, TValue>(TValue? Value = default) :
|
||||||
|
ISynchronize;
|
||||||
|
|
||||||
|
public record SynchronizeEventArgs<TSynchronize>() :
|
||||||
|
ISynchronize;
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
|
public record SynchronizeExpression(ISynchronize Value, object? Key = null);
|
||||||
Reference in New Issue
Block a user