wip
This commit is contained in:
@@ -1,23 +1,23 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public record Enumerate<TValue> : IEnumerate
|
||||
public record Enumerate<TValue> :
|
||||
IEnumerate
|
||||
{
|
||||
public object? Key { get; init; }
|
||||
|
||||
public EnumerateMode Mode { get; init; }
|
||||
|
||||
public static Enumerate<TValue, TOptions> With<TOptions>(TOptions options) where TOptions : class
|
||||
{
|
||||
return new Enumerate<TValue, TOptions>(options);
|
||||
}
|
||||
}
|
||||
|
||||
public interface IEnumerate
|
||||
{
|
||||
object? Key { get; init; }
|
||||
}
|
||||
|
||||
|
||||
public record Enumerate<TValue, TOptions>(TOptions? Options = null) : IEnumerate
|
||||
public record Enumerate<TValue, TOptions>(TOptions? Options = null) :
|
||||
IEnumerate
|
||||
where TOptions : class
|
||||
{
|
||||
public object? Key { get; init; }
|
||||
|
||||
public EnumerateMode Mode { get; init; }
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public enum EnumerateMode
|
||||
{
|
||||
Append,
|
||||
Reset
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
public interface IEnumerate
|
||||
{
|
||||
object? Key { get; init; }
|
||||
|
||||
EnumerateMode Mode { get; init; }
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
namespace Toolkit.Foundation;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false)]
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = true)]
|
||||
public class NotificationAttribute(object key) : Attribute
|
||||
{
|
||||
public object Key => key;
|
||||
}
|
||||
|
||||
public class EnumerateAttribute(object key,
|
||||
EnumerateMode mode = EnumerateMode.Reset) : NotificationAttribute(key)
|
||||
{
|
||||
public EnumerateMode Mode => mode;
|
||||
}
|
||||
@@ -310,17 +310,19 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
||||
|
||||
public async Task Enumerate()
|
||||
{
|
||||
Clear();
|
||||
if (this.GetAttribute<EnumerateAttribute>() is EnumerateAttribute attribute)
|
||||
{
|
||||
if (attribute.Mode == EnumerateMode.Reset)
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
object? key = this.GetAttribute<NotificationAttribute>()
|
||||
is NotificationAttribute attribute
|
||||
? this.GetPropertyValue(() => attribute.Key) is { } value ? value : attribute.Key
|
||||
: null;
|
||||
|
||||
await Publisher.PublishUI(CreateEnumeration(key));
|
||||
object? key = this.GetPropertyValue(() => attribute.Key) is { } value ? value : attribute.Key;
|
||||
await Publisher.PublishUI(PrepareEnumeration(key));
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual IEnumerate CreateEnumeration(object? key) =>
|
||||
protected virtual IEnumerate PrepareEnumeration(object? key) =>
|
||||
new Enumerate<TViewModel>() with { Key = key };
|
||||
|
||||
public void Insert(int index, TViewModel item) =>
|
||||
|
||||
@@ -73,4 +73,16 @@ public partial class ObservableViewModel :
|
||||
IsInitialized = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ObservableViewModel<TValue>(IServiceProvider provider,
|
||||
IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
IPublisher publisher,
|
||||
ISubscriber subscriber,
|
||||
IDisposer disposer) : ObservableViewModel(provider, factory, mediator, publisher, subscriber, disposer)
|
||||
where TValue : notnull
|
||||
{
|
||||
[ObservableProperty]
|
||||
private TValue? value;
|
||||
}
|
||||
@@ -54,7 +54,17 @@ public class SubscriptionManager(SubscriptionCollection subscriptions) :
|
||||
{
|
||||
if (interfaceType.GetGenericArguments().FirstOrDefault() is Type argumentType)
|
||||
{
|
||||
subscriptions.AddOrUpdate($"{(key is not null ? $"{key}:" : "")}{argumentType}", _ => new List<WeakReference> { new(subscriber) }, (_, collection) =>
|
||||
if (key is not null)
|
||||
{
|
||||
subscriptions.AddOrUpdate($"{key}:{argumentType}", _ => new List<WeakReference> { new(subscriber) }, (_, collection) =>
|
||||
{
|
||||
collection.Add(new WeakReference(subscriber));
|
||||
return collection;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
subscriptions.AddOrUpdate($"{argumentType}", _ => new List<WeakReference> { new(subscriber) }, (_, collection) =>
|
||||
{
|
||||
collection.Add(new WeakReference(subscriber));
|
||||
return collection;
|
||||
|
||||
Reference in New Issue
Block a user