Make it possible to feed in options to the Enumerate handler
This commit is contained in:
@@ -1,3 +1,23 @@
|
|||||||
namespace Toolkit.Foundation;
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
public record Enumerate<TValue>(object? Key = null);
|
public record Enumerate<TValue> : IEnumerate
|
||||||
|
{
|
||||||
|
public object? Key { 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
|
||||||
|
where TOptions : class
|
||||||
|
{
|
||||||
|
public object? Key { get; init; }
|
||||||
|
}
|
||||||
@@ -97,7 +97,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
|||||||
|
|
||||||
public TViewModel this[int index]
|
public TViewModel this[int index]
|
||||||
{
|
{
|
||||||
get => Count > 0 ? collection[index] : default;
|
get => collection[index];
|
||||||
set => SetItem(index, value);
|
set => SetItem(index, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,21 +299,30 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
|||||||
|
|
||||||
public async Task Initialize()
|
public async Task Initialize()
|
||||||
{
|
{
|
||||||
if (isInitialized)
|
if (IsInitialized)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
isInitialized = true;
|
IsInitialized = true;
|
||||||
|
await Enumerate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task Enumerate()
|
||||||
|
{
|
||||||
|
Clear();
|
||||||
|
|
||||||
object? key = this.GetAttribute<NotificationAttribute>()
|
object? key = this.GetAttribute<NotificationAttribute>()
|
||||||
is NotificationAttribute attribute
|
is NotificationAttribute attribute
|
||||||
? this.GetPropertyValue(() => attribute.Key) is { } value ? value : attribute.Key
|
? this.GetPropertyValue(() => attribute.Key) is { } value ? value : attribute.Key
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
await Publisher.PublishUI(new Enumerate<TViewModel>(key));
|
await Publisher.PublishUI(CreateEnumeration(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual IEnumerate CreateEnumeration(object? key) =>
|
||||||
|
new Enumerate<TViewModel>() with { Key = key };
|
||||||
|
|
||||||
public void Insert(int index, TViewModel item) =>
|
public void Insert(int index, TViewModel item) =>
|
||||||
InsertItem(index, item);
|
InsertItem(index, item);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Toolkit.Foundation;
|
namespace Toolkit.Foundation;
|
||||||
|
|
||||||
public record Selected<TValue>(TValue Value);
|
public record Selected<TValue>(TValue? Value);
|
||||||
|
|
||||||
public record Selected
|
public record Selected
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ public class SubscriptionManager(SubscriptionCollection subscriptions) :
|
|||||||
{
|
{
|
||||||
public IEnumerable<object?> GetHandlers(Type notificationType, object key)
|
public IEnumerable<object?> GetHandlers(Type notificationType, object key)
|
||||||
{
|
{
|
||||||
|
var d = subscriptions;
|
||||||
if (subscriptions.TryGetValue($"{(key is not null ? $"{key}:" : "")}{notificationType}",
|
if (subscriptions.TryGetValue($"{(key is not null ? $"{key}:" : "")}{notificationType}",
|
||||||
out List<WeakReference>? subscribers))
|
out List<WeakReference>? subscribers))
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user