using CommunityToolkit.Mvvm.ComponentModel; using Toolkit.Foundation; namespace Wallet; public partial class ItemEntryCollectionViewModel : ObservableCollection, IItemEntryViewModel, INotificationHandler>, INotificationHandler>, INotificationHandler> where TItem : notnull, IDisposable { [ObservableProperty] private ItemState state; private readonly ItemEntryConfiguration configuration; public ItemEntryCollectionViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, IPublisher publisher, ISubscriber subscriber, IDisposer disposer, ItemState state, ItemEntryConfiguration configuration, string key, object value, double width) : base(provider, factory, mediator, publisher, subscriber, disposer, key, value) { this.configuration = configuration; State = state; Width = width; } [ObservableProperty] private double width; public ItemEntryCollectionViewModel(IServiceProvider provider, IServiceFactory factory, IMediator mediator, IPublisher publisher, ISubscriber subscriber, IDisposer disposer, IEnumerable items, ItemState state, ItemEntryConfiguration configuration, string key, object value, double width) : base(provider, factory, mediator, publisher, subscriber, disposer, items, key, value) { this.configuration = configuration; State = state; Width = width; } protected override void OnValueChanged() { if (configuration is not null) { configuration.Value = Value; } } public Task Handle(UpdateEventArgs args) => Task.FromResult(State = ItemState.Write); public Task Handle(CancelEventArgs args) { Revert(); State = ItemState.Read; return Task.CompletedTask; } public Task Handle(ConfirmEventArgs args) { Commit(); State = ItemState.Read; return Task.CompletedTask; } }