Improved event naming

This commit is contained in:
TheXamlGuy
2024-05-12 19:55:20 +01:00
parent 9eafcc55d0
commit f0fd68c16e
56 changed files with 169 additions and 131 deletions
@@ -8,7 +8,7 @@ namespace Toolkit.Avalonia;
public class ClassicDesktopStyleApplicationHandler : public class ClassicDesktopStyleApplicationHandler :
INavigateHandler<IClassicDesktopStyleApplicationLifetime> INavigateHandler<IClassicDesktopStyleApplicationLifetime>
{ {
public Task Handle(Navigate<IClassicDesktopStyleApplicationLifetime> args, public Task Handle(NavigateEventArgs<IClassicDesktopStyleApplicationLifetime> args,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
if (Application.Current?.ApplicationLifetime is if (Application.Current?.ApplicationLifetime is
+3 -3
View File
@@ -7,7 +7,7 @@ namespace Toolkit.Avalonia;
public class ContentControlHandler : public class ContentControlHandler :
INavigateHandler<ContentControl> INavigateHandler<ContentControl>
{ {
public async Task Handle(Navigate<ContentControl> args, public async Task Handle(NavigateEventArgs<ContentControl> args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (args.Context is ContentControl contentControl) if (args.Context is ContentControl contentControl)
@@ -27,7 +27,7 @@ public class ContentControlHandler :
if (content is IActivated activated) if (content is IActivated activated)
{ {
await activated.Activated(); await activated.OnActivated();
} }
} }
@@ -41,7 +41,7 @@ public class ContentControlHandler :
{ {
if (content is IDeactivated deactivated) if (content is IDeactivated deactivated)
{ {
await deactivated.Deactivated(); await deactivated.OnDeactivated();
} }
} }
} }
+2 -2
View File
@@ -6,7 +6,7 @@ namespace Toolkit.Avalonia;
public class ContentDialogHandler(IDispatcher dispatcher) : public class ContentDialogHandler(IDispatcher dispatcher) :
INavigateHandler<ContentDialog> INavigateHandler<ContentDialog>
{ {
public async Task Handle(Navigate<ContentDialog> args, public async Task Handle(NavigateEventArgs<ContentDialog> args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (args.Context is ContentDialog contentDialog) if (args.Context is ContentDialog contentDialog)
@@ -94,7 +94,7 @@ public class ContentDialogHandler(IDispatcher dispatcher) :
if (content is IActivated activated) if (content is IActivated activated)
{ {
await activated.Activated(); await activated.OnActivated();
} }
} }
} }
+2 -2
View File
@@ -35,7 +35,7 @@ public class ContentTemplate :
if (content is IActivated activated) if (content is IActivated activated)
{ {
await activated.Activated(); await activated.OnActivated();
} }
} }
} }
@@ -47,7 +47,7 @@ public class ContentTemplate :
{ {
if (content is IDeactivated deactivated) if (content is IDeactivated deactivated)
{ {
await deactivated.Deactivated(); await deactivated.OnDeactivated();
} }
} }
} }
+5 -5
View File
@@ -12,7 +12,7 @@ public class FrameHandler :
INavigateHandler<Frame>, INavigateHandler<Frame>,
INavigateBackHandler<Frame> INavigateBackHandler<Frame>
{ {
public Task Handle(Navigate<Frame> args, public Task Handle(NavigateEventArgs<Frame> args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (args.Context is Frame frame) if (args.Context is Frame frame)
@@ -43,7 +43,7 @@ public class FrameHandler :
{ {
if (content is IDeactivating deactivating) if (content is IDeactivating deactivating)
{ {
await deactivating.Deactivating(); await deactivating.OnDeactivating();
} }
} }
} }
@@ -72,7 +72,7 @@ public class FrameHandler :
{ {
if (content is IDeactivated deactivated) if (content is IDeactivated deactivated)
{ {
await deactivated.Deactivated(); await deactivated.OnDeactivated();
} }
} }
} }
@@ -119,7 +119,7 @@ public class FrameHandler :
if (content is IActivated activated) if (content is IActivated activated)
{ {
await activated.Activated(); await activated.OnActivated();
} }
} }
} }
@@ -136,7 +136,7 @@ public class FrameHandler :
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Handle(NavigateBack<Frame> args, public Task Handle(NavigateBackEventArgs<Frame> args,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
if (args.Context is Frame frame) if (args.Context is Frame frame)
@@ -8,7 +8,7 @@ namespace Toolkit.Avalonia;
public class SingleViewApplicationHandler : public class SingleViewApplicationHandler :
INavigateHandler<ISingleViewApplicationLifetime> INavigateHandler<ISingleViewApplicationLifetime>
{ {
public Task Handle(Navigate<ISingleViewApplicationLifetime> args, public Task Handle(NavigateEventArgs<ISingleViewApplicationLifetime> args,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
if (Application.Current?.ApplicationLifetime is if (Application.Current?.ApplicationLifetime is
+8
View File
@@ -0,0 +1,8 @@
namespace Toolkit.Foundation;
public record Activate
{
public static ActivateEventArgs<TValue> As<TValue>(TValue value) => new(value);
public static ActivateEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
}
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record ActivateEventArgs<TValue>(TValue? Value = default);
+2 -4
View File
@@ -1,10 +1,8 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Activated<TValue>(TValue? Value = default);
public record Activated public record Activated
{ {
public static Activated<TValue> As<TValue>(TValue value) => new(value); public static ActivatedEventArgs<TValue> As<TValue>(TValue value) => new(value);
public static Activated<TValue> As<TValue>() where TValue : new() => new(new TValue()); public static ActivatedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record ActivatedEventArgs<TValue>(TValue? Value = default);
+1 -1
View File
@@ -13,7 +13,7 @@ public class AppService(IEnumerable<IInitializer> initializers,
await initializer.Initialize(); await initializer.Initialize();
} }
await publisher.Publish<Started>(cancellationToken); await publisher.Publish<StartedEventArgs>(cancellationToken);
} }
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask; public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
+2 -4
View File
@@ -1,10 +1,8 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Changed<TValue>(TValue? Value = default);
public record Changed public record Changed
{ {
public static Changed<TValue> As<TValue>(TValue value) => new(value); public static ChangedEventArgs<TValue> As<TValue>(TValue value) => new(value);
public static Changed<TValue> As<TValue>() where TValue : new() => new(new TValue()); public static ChangedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record ChangedEventArgs<TValue>(TValue? Value = default);
@@ -5,7 +5,7 @@ namespace Toolkit.Foundation;
public partial class ComponentConfigurationViewModel<TConfiguration, TValue, THeader, TDescription, TAction> : public partial class ComponentConfigurationViewModel<TConfiguration, TValue, THeader, TDescription, TAction> :
ValueViewModel<TValue>, ValueViewModel<TValue>,
IComponentConfigurationViewModel, IComponentConfigurationViewModel,
INotificationHandler<Changed<TConfiguration>> INotificationHandler<ChangedEventArgs<TConfiguration>>
where TConfiguration : class where TConfiguration : class
{ {
public ComponentConfigurationViewModel(IServiceProvider provider, public ComponentConfigurationViewModel(IServiceProvider provider,
@@ -20,7 +20,7 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, THe
{ {
} }
public Task Handle(Changed<TConfiguration> args, public Task Handle(ChangedEventArgs<TConfiguration> args,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
@@ -40,7 +40,7 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TAc
object description) : object description) :
ValueViewModel<TValue>(provider, factory, mediator, publisher, subscriber, disposer), ValueViewModel<TValue>(provider, factory, mediator, publisher, subscriber, disposer),
IComponentConfigurationViewModel, IComponentConfigurationViewModel,
INotificationHandler<Changed<TConfiguration>> INotificationHandler<ChangedEventArgs<TConfiguration>>
where TConfiguration : class where TConfiguration : class
{ {
[ObservableProperty] [ObservableProperty]
@@ -52,13 +52,13 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TAc
[ObservableProperty] [ObservableProperty]
private object description = description; private object description = description;
public override Task Activated() public override Task OnActivated()
{ {
Value = valueDelegate.Invoke(configuration); Value = valueDelegate.Invoke(configuration);
return base.Activated(); return base.OnActivated();
} }
public Task Handle(Changed<TConfiguration> args, public Task Handle(ChangedEventArgs<TConfiguration> args,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
if (args.Value is TConfiguration configuration) if (args.Value is TConfiguration configuration)
@@ -83,7 +83,7 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TDe
object header) : object header) :
ValueViewModel<TValue>(provider, factory, mediator, publisher, subscriber, disposer), ValueViewModel<TValue>(provider, factory, mediator, publisher, subscriber, disposer),
IComponentConfigurationViewModel, IComponentConfigurationViewModel,
INotificationHandler<Changed<TConfiguration>> INotificationHandler<ChangedEventArgs<TConfiguration>>
where TConfiguration : class where TConfiguration : class
{ {
[ObservableProperty] [ObservableProperty]
@@ -95,13 +95,13 @@ public partial class ComponentConfigurationViewModel<TConfiguration, TValue, TDe
[ObservableProperty] [ObservableProperty]
private TDescription description = description; private TDescription description = description;
public override Task Activated() public override Task OnActivated()
{ {
Value = valueDelegate.Invoke(configuration); Value = valueDelegate.Invoke(configuration);
return base.Activated(); return base.OnActivated();
} }
public Task Handle(Changed<TConfiguration> args, public Task Handle(ChangedEventArgs<TConfiguration> args,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
if (args.Value is TConfiguration configuration) if (args.Value is TConfiguration configuration)
@@ -1,11 +1,11 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public class ConfigurationChangedHandler<TConfiguration, TValue>(ConfigurationValue<TConfiguration, TValue> configurationValue) : public class ConfigurationChangedHandler<TConfiguration, TValue>(ConfigurationValue<TConfiguration, TValue> configurationValue) :
INotificationHandler<Changed<TConfiguration>> INotificationHandler<ChangedEventArgs<TConfiguration>>
where TValue : where TValue :
class, new() class, new()
{ {
public Task Handle(Changed<TConfiguration> args, public Task Handle(ChangedEventArgs<TConfiguration> args,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
if (args.Value is TConfiguration configuration) if (args.Value is TConfiguration configuration)
@@ -20,6 +20,6 @@ public class ConfigurationInitializer<TConfiguration>(IConfigurationReader<TConf
} }
} }
await publisher.PublishUI(new Activated<TConfiguration>(configuration)); await publisher.PublishUI(new ActivatedEventArgs<TConfiguration>(configuration));
} }
} }
+1 -1
View File
@@ -16,7 +16,7 @@ public class ConfigurationMonitor<TConfiguration>(IConfigurationFile<TConfigurat
{ {
if (reader.Read() is { } configuration) if (reader.Read() is { } configuration)
{ {
await publisher.PublishUI(new Changed<TConfiguration>(configuration)); await publisher.PublishUI(new ChangedEventArgs<TConfiguration>(configuration));
} }
} }
+2 -4
View File
@@ -1,12 +1,10 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Confirm<TValue>(TValue Value);
public record Confirm public record Confirm
{ {
public static Confirm<TValue> As<TValue>(TValue value) => public static ConfirmEventArgs<TValue> As<TValue>(TValue value) =>
new(value); new(value);
public static Confirm<TValue> As<TValue>() where TValue : new() => public static ConfirmEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue()); new(new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record ConfirmEventArgs<TValue>(TValue Value);
+2 -4
View File
@@ -1,12 +1,10 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Create<TValue>(TValue Value);
public record Create public record Create
{ {
public static Create<TValue> As<TValue>(TValue value) => public static CreateEventArgs<TValue> As<TValue>(TValue value) =>
new(value); new(value);
public static Create<TValue> As<TValue>() where TValue : new() => public static CreateEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue()); new(new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record CreateEventArgs<TValue>(TValue Value);
+6 -1
View File
@@ -1,3 +1,8 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Deactivated; public record Deactivated
{
public static DeactivatedEventArgs<TValue> As<TValue>(TValue value) => new(value);
public static DeactivatedEventArgs<TValue> As<TValue>() where TValue : new() => new(new TValue());
}
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record DeactivatedEventArgs<TValue>(TValue? Value = default);
-13
View File
@@ -1,18 +1,5 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
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 record Enumerate<TValue, TOptions>(TOptions? Options = null) : public record Enumerate<TValue, TOptions>(TOptions? Options = null) :
IEnumerate IEnumerate
where TOptions : class where TOptions : class
+14
View File
@@ -0,0 +1,14 @@
namespace Toolkit.Foundation;
public record EnumerateEventArgs<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);
}
}
+1 -1
View File
@@ -2,7 +2,7 @@
public interface IActivated public interface IActivated
{ {
Task Activated(); Task OnActivated();
} }
public interface IActivated<TResult> public interface IActivated<TResult>
+1 -1
View File
@@ -2,5 +2,5 @@
public interface IDeactivated public interface IDeactivated
{ {
Task Deactivated(); Task OnDeactivated();
} }
+1 -1
View File
@@ -2,7 +2,7 @@
public interface IDeactivating public interface IDeactivating
{ {
Task Deactivating(); Task OnDeactivating();
} }
public interface IDeactivating<TResult> public interface IDeactivating<TResult>
+1 -1
View File
@@ -1,5 +1,5 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public interface INavigateBackHandler<TNavigation> : public interface INavigateBackHandler<TNavigation> :
INotificationHandler<NavigateBack<TNavigation>>, INotificationHandler<NavigateBackEventArgs<TNavigation>>,
INavigateHandler; INavigateHandler;
+1 -1
View File
@@ -3,5 +3,5 @@
public interface INavigateHandler; public interface INavigateHandler;
public interface INavigateHandler<TNavigation> : public interface INavigateHandler<TNavigation> :
INotificationHandler<Navigate<TNavigation>>, INotificationHandler<NavigateEventArgs<TNavigation>>,
INavigateHandler; INavigateHandler;
+2 -4
View File
@@ -1,12 +1,10 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Insert<TValue>(int Index, TValue Value);
public record Insert public record Insert
{ {
public static Insert<TValue> As<TValue>(int index, TValue value) => public static InsertEventArgs<TValue> As<TValue>(int index, TValue value) =>
new(index, value); new(index, value);
public static Insert<TValue> As<TValue>(int index) where TValue : new() => public static InsertEventArgs<TValue> As<TValue>(int index) where TValue : new() =>
new(index, new TValue()); new(index, new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record InsertEventArgs<TValue>(int Index, TValue Value);
+2 -4
View File
@@ -1,12 +1,10 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Move<TValue>(int Index, TValue Value);
public record Move public record Move
{ {
public static Move<TValue> As<TValue>(int index, TValue value) => public static MoveEventArgs<TValue> As<TValue>(int index, TValue value) =>
new(index, value); new(index, value);
public static Insert<TValue> As<TValue>(int index) where TValue : new() => public static InsertEventArgs<TValue> As<TValue>(int index) where TValue : new() =>
new(index, new TValue()); new(index, new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record MoveEventArgs<TValue>(int Index, TValue Value);
-5
View File
@@ -1,5 +0,0 @@
namespace Toolkit.Foundation;
public record NavigateBack(object? Context = null, string? Scope = null);
public record NavigateBack<TNavigation>(object? Context);
@@ -0,0 +1,5 @@
namespace Toolkit.Foundation;
public record NavigateBackEventArgs(object? Context = null, string? Scope = null);
public record NavigateBackEventArgs<TNavigation>(object? Context);
+2 -2
View File
@@ -3,9 +3,9 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public class NavigateBackHandler(IComponentScopeProvider provider) : public class NavigateBackHandler(IComponentScopeProvider provider) :
INotificationHandler<NavigateBack> INotificationHandler<NavigateBackEventArgs>
{ {
public async Task Handle(NavigateBack args, public async Task Handle(NavigateBackEventArgs args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (provider.Get(args.Scope ?? "Root") if (provider.Get(args.Scope ?? "Root")
+14
View File
@@ -0,0 +1,14 @@
namespace Toolkit.Foundation;
public record NavigateEventArgs(string Route,
object? Context = null,
string? Scope = null,
object? Sender = null,
EventHandler? Navigated = null,
object[]? Parameters = null);
public record NavigateEventArgs<TNavigation>(object Context,
object Template,
object Content,
object? Sender = null,
object[]? Parameters = null);
+2 -2
View File
@@ -5,9 +5,9 @@ namespace Toolkit.Foundation;
public class NavigateHandler(NamedComponent scope, public class NavigateHandler(NamedComponent scope,
IComponentScopeProvider componentScopeProvider, IComponentScopeProvider componentScopeProvider,
IServiceProvider provider) : IServiceProvider provider) :
INotificationHandler<Navigate> INotificationHandler<NavigateEventArgs>
{ {
public async Task Handle(Navigate args, public async Task Handle(NavigateEventArgs args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
INavigationScope? navigationScope; INavigationScope? navigationScope;
-3
View File
@@ -1,3 +0,0 @@
namespace Toolkit.Foundation;
public record NavigationChanged<TValue>(TValue? Value);
+2 -2
View File
@@ -62,7 +62,7 @@ public class NavigationScope(IPublisher publisher,
if (navigationProvider.Get(context is Type type ? type : context.GetType()) if (navigationProvider.Get(context is Type type ? type : context.GetType())
is INavigation navigation) is INavigation navigation)
{ {
Type navigateType = typeof(Navigate<>).MakeGenericType(navigation.Type); Type navigateType = typeof(NavigateEventArgs<>).MakeGenericType(navigation.Type);
if (Activator.CreateInstance(navigateType, [context, view, viewModel, sender, parameters]) is object navigate) if (Activator.CreateInstance(navigateType, [context, view, viewModel, sender, parameters]) is object navigate)
{ {
await publisher.Publish(navigate, cancellationToken); await publisher.Publish(navigate, cancellationToken);
@@ -92,7 +92,7 @@ public class NavigationScope(IPublisher publisher,
if (navigationProvider.Get(context is Type type ? type : context.GetType()) if (navigationProvider.Get(context is Type type ? type : context.GetType())
is INavigation navigation) is INavigation navigation)
{ {
Type navigateType = typeof(NavigateBack<>).MakeGenericType(navigation.Type); Type navigateType = typeof(NavigateBackEventArgs<>).MakeGenericType(navigation.Type);
if (Activator.CreateInstance(navigateType, [context]) is object navigate) if (Activator.CreateInstance(navigateType, [context]) is object navigate)
{ {
await publisher.Publish(navigate, cancellationToken); await publisher.Publish(navigate, cancellationToken);
@@ -19,11 +19,11 @@ public partial class ObservableCollectionViewModel<TViewModel> :
IList, IList,
IReadOnlyList<TViewModel>, IReadOnlyList<TViewModel>,
INotifyCollectionChanged, INotifyCollectionChanged,
INotificationHandler<Remove<TViewModel>>, INotificationHandler<RemoveEventArgs<TViewModel>>,
INotificationHandler<Create<TViewModel>>, INotificationHandler<CreateEventArgs<TViewModel>>,
INotificationHandler<Insert<TViewModel>>, INotificationHandler<InsertEventArgs<TViewModel>>,
INotificationHandler<Move<TViewModel>>, INotificationHandler<MoveEventArgs<TViewModel>>,
INotificationHandler<Replace<TViewModel>> INotificationHandler<ReplaceEventArgs<TViewModel>>
where TViewModel : where TViewModel :
notnull notnull
{ {
@@ -121,7 +121,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
} }
} }
public virtual Task Activated() => public virtual Task OnActivated() =>
Task.CompletedTask; Task.CompletedTask;
public TViewModel Add() public TViewModel Add()
@@ -222,10 +222,10 @@ public partial class ObservableCollectionViewModel<TViewModel> :
return Task.CompletedTask; return Task.CompletedTask;
} }
public virtual Task Deactivated() => public virtual Task OnDeactivated() =>
Task.CompletedTask; Task.CompletedTask;
public virtual Task Deactivating() => public virtual Task OnDeactivating() =>
Task.CompletedTask; Task.CompletedTask;
public virtual void Dispose() public virtual void Dispose()
@@ -240,7 +240,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
IEnumerator IEnumerable.GetEnumerator() => IEnumerator IEnumerable.GetEnumerator() =>
((IEnumerable)collection).GetEnumerator(); ((IEnumerable)collection).GetEnumerator();
public Task Handle(Remove<TViewModel> args, public Task Handle(RemoveEventArgs<TViewModel> args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
foreach (TViewModel item in this.ToList()) foreach (TViewModel item in this.ToList())
@@ -254,7 +254,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Handle(Create<TViewModel> args, public Task Handle(CreateEventArgs<TViewModel> args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (args.Value is TViewModel item) if (args.Value is TViewModel item)
@@ -265,7 +265,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Handle(Insert<TViewModel> args, public Task Handle(InsertEventArgs<TViewModel> args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (args.Value is TViewModel item) if (args.Value is TViewModel item)
@@ -276,7 +276,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Handle(Move<TViewModel> args, public Task Handle(MoveEventArgs<TViewModel> args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (args.Value is TViewModel item) if (args.Value is TViewModel item)
@@ -287,7 +287,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
return Task.CompletedTask; return Task.CompletedTask;
} }
public Task Handle(Replace<TViewModel> args, public Task Handle(ReplaceEventArgs<TViewModel> args,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (args.Value is TViewModel item) if (args.Value is TViewModel item)
@@ -332,7 +332,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
} }
protected virtual IEnumerate PrepareEnumeration(object? key) => protected virtual IEnumerate PrepareEnumeration(object? key) =>
new Enumerate<TViewModel>() with { Key = key }; new EnumerateEventArgs<TViewModel>() with { Key = key };
public void Insert(int index, TViewModel item) => public void Insert(int index, TViewModel item) =>
InsertItem(index, item); InsertItem(index, item);
+3 -3
View File
@@ -42,7 +42,7 @@ public partial class ObservableViewModel :
public IPublisher Publisher { get; } public IPublisher Publisher { get; }
public virtual Task Activated() => public virtual Task OnActivated() =>
Task.CompletedTask; Task.CompletedTask;
public Task Deactivate() public Task Deactivate()
@@ -51,10 +51,10 @@ public partial class ObservableViewModel :
return Task.CompletedTask; return Task.CompletedTask;
} }
public virtual Task Deactivated() => public virtual Task OnDeactivated() =>
Task.CompletedTask; Task.CompletedTask;
public virtual Task Deactivating() => public virtual Task OnDeactivating() =>
Task.CompletedTask; Task.CompletedTask;
public void Dispose() public void Dispose()
-10
View File
@@ -1,10 +0,0 @@
namespace Toolkit.Foundation;
public record Open<TValue>(TValue Value);
public record Open
{
public static Open<TValue> As<TValue>(TValue value) => new(value);
public static Open<TValue> As<TValue>() where TValue : new() => new(new TValue());
}
+2 -4
View File
@@ -1,12 +1,10 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Remove<TValue>(TValue Value);
public record Remove public record Remove
{ {
public static Remove<TValue> As<TValue>(TValue value) => public static RemoveEventArgs<TValue> As<TValue>(TValue value) =>
new(value); new(value);
public static Remove<TValue> As<TValue>() where TValue : new() => public static RemoveEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue()); new(new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record RemoveEventArgs<TValue>(TValue Value);
+2 -4
View File
@@ -1,12 +1,10 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Replace<TValue>(int Index, TValue Value);
public record Replace public record Replace
{ {
public static Replace<TValue> As<TValue>(int index, TValue value) => public static ReplaceEventArgs<TValue> As<TValue>(int index, TValue value) =>
new(index, value); new(index, value);
public static Replace<TValue> As<TValue>(int index) where TValue : new() => public static ReplaceEventArgs<TValue> As<TValue>(int index) where TValue : new() =>
new(index, new TValue()); new(index, new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record ReplaceEventArgs<TValue>(int Index, TValue Value);
+5 -3
View File
@@ -1,8 +1,10 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Request<TValue>;
public class Request public class Request
{ {
public static Request<TValue> As<TValue>() => new(); public static RequestEventArgs<TValue> As<TValue>(TValue value) =>
new(value);
public static RequestEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record RequestEventArgs<TValue>(TValue Value);
+2 -4
View File
@@ -1,12 +1,10 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Selected<TValue>(TValue? Value);
public record Selected public record Selected
{ {
public static Selected<TValue> As<TValue>(TValue value) => public static SelectedEventArgs<TValue> As<TValue>(TValue value) =>
new(value); new(value);
public static Selected<TValue> As<TValue>() where TValue : new() => public static SelectedEventArgs<TValue> As<TValue>() where TValue : new() =>
new(new TValue()); new(new TValue());
} }
+3
View File
@@ -0,0 +1,3 @@
namespace Toolkit.Foundation;
public record SelectedEventArgs<TValue>(TValue? Value);
@@ -1,3 +1,3 @@
namespace Toolkit.Foundation; namespace Toolkit.Foundation;
public record Started; public record StartedEventArgs;
@@ -4,6 +4,9 @@
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="Navigate.cs" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" /> <PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0-preview.3.24172.9" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0-preview.3.24172.9" />
+1 -1
View File
@@ -74,7 +74,7 @@ public class NavigateAction :
ParameterBindings.Select(binding => new KeyValuePair<string, object>(binding.Key, binding.Value)).ToArray() : ParameterBindings.Select(binding => new KeyValuePair<string, object>(binding.Key, binding.Value)).ToArray() :
Enumerable.Empty<KeyValuePair<string, object>>()]; Enumerable.Empty<KeyValuePair<string, object>>()];
observableViewModel.Publisher.Publish(new Navigate(Route, Context == this ? control : Context, Scope ?? null, observableViewModel.Publisher.Publish(new NavigateEventArgs(Route, Context == this ? control : Context, Scope ?? null,
control.DataContext, Navigated, parameters)).ConfigureAwait(false); control.DataContext, Navigated, parameters)).ConfigureAwait(false);
} }
} }
+1 -1
View File
@@ -34,7 +34,7 @@ public class NavigateBackAction :
{ {
if (control.DataContext is IObservableViewModel observableViewModel) if (control.DataContext is IObservableViewModel observableViewModel)
{ {
observableViewModel.Publisher.Publish(new NavigateBack(Context observableViewModel.Publisher.Publish(new NavigateBackEventArgs(Context
?? null, Scope ?? null)).ConfigureAwait(false); ?? null, Scope ?? null)).ConfigureAwait(false);
} }
} }