From be3a40d5260b8c53e5fcf0f074968316dd0ae833 Mon Sep 17 00:00:00 2001 From: Bernhard Straub Date: Sat, 20 Apr 2024 14:59:21 +0200 Subject: [PATCH] RX State all new State handing Synchronized changing --- .../Component/RxBLServiceContext.cs | 9 +++- .../Component/RxBLServiceSubscriber.cs | 21 ++------- RxBlazorLightCore/Core/Interfaces.cs | 4 +- RxBlazorLightCore/Core/RxExtensions.cs | 35 ++++++++++++-- RxBlazorLightCore/Core/Service.cs | 26 ++++++---- RxBlazorLightCore/Core/ServiceExtensions.cs | 5 +- RxBlazorLightCore/Core/State.cs | 47 ++++++++++--------- .../RxBlazorLightCore.csproj.DotSettings | 2 - RxMudBlazorLight/ButtonBase/ButtonBaseRx.cs | 1 - RxMudBlazorLight/ButtonBase/ButtonRx.cs | 6 +-- .../Dialogs/DialogAsyncRx.razor.cs | 2 +- RxMudBlazorLight/Dialogs/DialogRx.razor.cs | 2 +- .../Inputs/MudAutocompleteRx.razor | 4 +- RxMudBlazorLight/Inputs/MudCheckBoxRx.razor | 4 +- RxMudBlazorLight/Inputs/MudDatePickerRx.razor | 4 +- .../Inputs/MudNumericFieldRx.razor | 4 +- RxMudBlazorLight/Inputs/MudRatingRx.razor | 4 +- RxMudBlazorLight/Inputs/MudSliderRx.razor | 4 +- RxMudBlazorLight/Inputs/MudSwitchRx.razor | 4 +- RxMudBlazorLight/Inputs/MudTextFieldRx.razor | 4 +- RxMudBlazorLight/Inputs/MudTimePickerRx.razor | 4 +- .../Inputs/Radio/MudRadioGroupAsyncRx.razor | 2 +- .../Inputs/Radio/MudRadioGroupRx.razor | 2 +- .../Inputs/Select/MudSelectAsyncRx.razor | 2 +- .../Inputs/Select/MudSelectRx.razor | 2 +- .../MudToggleIconButtonRx.razor | 4 +- .../Components/InputTest.razor | 4 +- .../Components/TestPlayground.razor | 2 +- .../Service/CrudService.cs | 6 +-- .../Service/TestService.State.cs | 2 +- 30 files changed, 123 insertions(+), 99 deletions(-) delete mode 100644 RxBlazorLightCore/RxBlazorLightCore.csproj.DotSettings diff --git a/RxBlazorLightCore/Component/RxBLServiceContext.cs b/RxBlazorLightCore/Component/RxBLServiceContext.cs index 71bcd46..0e1bc10 100644 --- a/RxBlazorLightCore/Component/RxBLServiceContext.cs +++ b/RxBlazorLightCore/Component/RxBLServiceContext.cs @@ -17,7 +17,9 @@ protected override void OnInitialized() { foreach (var type in ServiceCollector.ServiceTypes) { - ActivatorUtilities.CreateInstance(ServiceProvider, type); + var service = ActivatorUtilities.CreateInstance(ServiceProvider, type) as IRxBLService; + ArgumentNullException.ThrowIfNull(service); + ServiceCollector.AddService(service); } } base.OnInitialized(); @@ -29,7 +31,10 @@ protected override async Task OnAfterRenderAsync(bool firstRender) { foreach (var service in ServiceCollector.Services) { - await service.OnContextReadyAsync(); + if (!service.Initialized) + { + await service.OnContextReadyAsync(); + } } } diff --git a/RxBlazorLightCore/Component/RxBLServiceSubscriber.cs b/RxBlazorLightCore/Component/RxBLServiceSubscriber.cs index 420fdb5..38d02c3 100644 --- a/RxBlazorLightCore/Component/RxBLServiceSubscriber.cs +++ b/RxBlazorLightCore/Component/RxBLServiceSubscriber.cs @@ -18,34 +18,21 @@ protected override void OnInitialized() .Sample(TimeSpan.FromMilliseconds(SampleRateMS)) .Select(async cr => { - await ServiceStateHasChangedAsync(cr); - ServiceStateHasChanged(cr); + await OnServiceStateHasChangedAsync(cr); + OnServiceStateHasChanged(cr); await InvokeAsync(StateHasChanged); }) .Subscribe(); } - protected virtual void ServiceStateHasChanged(ServiceChangeReason cr) + protected virtual void OnServiceStateHasChanged(ServiceChangeReason cr) { } - protected virtual Task ServiceStateHasChangedAsync(ServiceChangeReason cr) + protected virtual Task OnServiceStateHasChangedAsync(ServiceChangeReason cr) { return Task.CompletedTask; } - - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - if (!Service.Initialized) - { - await Service.OnContextReadyAsync(); - } - } - - await base.OnAfterRenderAsync(firstRender); - } } public class RxBLServiceSubscriber : ComponentBase where T1 : IRxBLService where T2 : IRxBLService diff --git a/RxBlazorLightCore/Core/Interfaces.cs b/RxBlazorLightCore/Core/Interfaces.cs index 308ab3e..d9aa192 100644 --- a/RxBlazorLightCore/Core/Interfaces.cs +++ b/RxBlazorLightCore/Core/Interfaces.cs @@ -18,13 +18,12 @@ public interface IRxBLStateScope : IDisposable public ValueTask OnContextReadyAsync(); } - public interface IRxBLService : IObservable, IObserver + public interface IRxBLService : IObservable, IObserver, IStateInformation { public ValueTask OnContextReadyAsync(); public bool Initialized { get; } public IEnumerable Exceptions { get; } public void ResetExceptions(); - public Guid ID { get; } public void StateHasChanged(); public IStateCommand Command { get; } public IStateCommandAsync CommandAsync { get; } @@ -43,6 +42,7 @@ public interface IStateInformation { public StatePhase Phase { get; } public Guid ID { get; } + public bool Disabled { get; } } public interface IState : IStateInformation diff --git a/RxBlazorLightCore/Core/RxExtensions.cs b/RxBlazorLightCore/Core/RxExtensions.cs index b4aa340..a08ca3c 100644 --- a/RxBlazorLightCore/Core/RxExtensions.cs +++ b/RxBlazorLightCore/Core/RxExtensions.cs @@ -5,27 +5,52 @@ public static class RxExtensions { public static IState CreateState(this RxBLService service, T value) { - return State.Create(service, value); + return State.Create(service, value, false); + } + + public static IState CreateIndependentState(this RxBLService service, T value) + { + return State.Create(service, value, true); } public static IStateCommand CreateStateCommand(this RxBLService service) { - return StateCommand.Create(service); + return StateCommand.Create(service, false); + } + + public static IStateCommand CreateIndependentStateCommand(this RxBLService service) + { + return StateCommand.Create(service, true); } public static IStateCommandAsync CreateStateCommandAsync(this RxBLService service, bool canCancel = false) { - return StateCommandAsync.Create(service, canCancel); + return StateCommandAsync.Create(service, canCancel, false); + } + + public static IStateCommandAsync CreateIndependentStateCommandAsync(this RxBLService service, bool canCancel = false) + { + return StateCommandAsync.Create(service, canCancel, true); } public static IStateGroup CreateStateGroup(this RxBLService service, T[] items, T? value = default) { - return StateGroup.Create(service, items, value); + return StateGroup.Create(service, items, value, false); + } + + public static IStateGroup CreateIndependentStateGroup(this RxBLService service, T[] items, T? value = default) + { + return StateGroup.Create(service, items, value, true); } public static IStateGroupAsync CreateStateGroupAsync(this RxBLService service, T[] items, T? value = default) { - return StateGroupAsync.Create(service, items, value); + return StateGroupAsync.Create(service, items, value, false); + } + + public static IStateGroupAsync CreateIndependentStateGroupAsync(this RxBLService service, T[] items, T? value = default) + { + return StateGroupAsync.Create(service, items, value, true); } public static bool Changing(this IStateInformation state) diff --git a/RxBlazorLightCore/Core/Service.cs b/RxBlazorLightCore/Core/Service.cs index 9c4f3bc..637a1a2 100644 --- a/RxBlazorLightCore/Core/Service.cs +++ b/RxBlazorLightCore/Core/Service.cs @@ -1,5 +1,4 @@ -using System; -using System.Reactive; +using System.Reactive; using System.Reactive.Linq; using System.Reactive.Subjects; @@ -34,6 +33,8 @@ public class RxBLService : IRxBLService public IStateCommand Command { get; } public IStateCommandAsync CommandAsync { get; } public IStateCommandAsync CancellableCommandAsync { get; } + public StatePhase Phase { get; private set; } = StatePhase.CHANGED; + public bool Disabled => Phase is not StatePhase.CHANGING; private readonly Subject _changedSubject = new(); private readonly IObservable _changedObservable; @@ -52,19 +53,28 @@ public RxBLService() public void StateHasChanged() { - StateHasChanged(ID); + StateHasChanged(this); } - internal void StateHasChanged(Guid id, Exception? exception = null) + internal void StateHasChanged(IStateInformation stateInfo, Exception? exception = null) { if (exception is not null) { - _serviceExceptions.Add(new(id, exception)); - _changedSubject.OnNext(new(id, ChangeReason.EXCEPTION)); + _serviceExceptions.Add(new(stateInfo.ID, exception)); + _changedSubject.OnNext(new(stateInfo.ID, ChangeReason.EXCEPTION)); } else { - _changedSubject.OnNext(new(id, ChangeReason.STATE)); + _changedSubject.OnNext(new(stateInfo.ID, ChangeReason.STATE)); + } + + if (stateInfo.Changing()) + { + Phase = StatePhase.CHANGING; + } + else + { + Phase = StatePhase.CHANGED; } } @@ -81,7 +91,7 @@ public async ValueTask OnContextReadyAsync() } await ContextReadyAsync(); Initialized = true; - StateHasChanged(ID); + StateHasChanged(this); } protected virtual ValueTask ContextReadyAsync() diff --git a/RxBlazorLightCore/Core/ServiceExtensions.cs b/RxBlazorLightCore/Core/ServiceExtensions.cs index 54118bf..c438fb4 100644 --- a/RxBlazorLightCore/Core/ServiceExtensions.cs +++ b/RxBlazorLightCore/Core/ServiceExtensions.cs @@ -13,7 +13,7 @@ public class RxServiceCollector private readonly List _serviceTypes = []; - internal void AddService(T service) where T : IRxBLService + internal void AddService(IRxBLService service) { _services.Add(service); } @@ -37,8 +37,6 @@ public static RxServiceCollector AddRxBLServiceCollector(this IServiceCollection { var service = new T(); services.AddSingleton(service); - collector.AddService(service); - return services; } @@ -49,7 +47,6 @@ public static IServiceCollection AddRxBLService(this IServiceCollection servi services.AddSingleton(sp => { var service = serviceFactory(sp); - collector.AddService(service); return service; }); diff --git a/RxBlazorLightCore/Core/State.cs b/RxBlazorLightCore/Core/State.cs index 8875669..6a20d29 100644 --- a/RxBlazorLightCore/Core/State.cs +++ b/RxBlazorLightCore/Core/State.cs @@ -2,17 +2,20 @@ namespace RxBlazorLightCore { - public class StateBase + public class StateBase : IStateInformation { public StatePhase Phase { get; private set; } = StatePhase.CHANGED; public Guid ID { get; } = Guid.NewGuid(); + public bool Disabled => _independent ? Phase is StatePhase.CHANGING : _service.Changing(); protected readonly RxBLService _service; private bool _notifyChanging = true; + private bool _independent = true; - protected StateBase(RxBLService service) + protected StateBase(RxBLService service, bool independent) { _service = service; + _independent = independent; } public void NotifyChanging() @@ -53,7 +56,7 @@ protected void PhaseChanged(bool changed, bool notify = true, Exception? excepti if (notify || _notifyChanging || exception is not null) { - _service.StateHasChanged(ID, exception); + _service.StateHasChanged(this, exception); _notifyChanging = notify; } } @@ -73,7 +76,7 @@ public T Value private T _value; - protected State(RxBLService service, T value) : base(service) + protected State(RxBLService service, T value, bool independent) : base(service, independent) { _value = value; } @@ -89,15 +92,15 @@ public bool HasValue() return Value is not null; } - public static IState Create(RxBLService service, T value) + public static IState Create(RxBLService service, T value, bool independent) { - return new State(service, value); + return new State(service, value, independent); } } public class StateCommand : StateBase, IStateCommand { - protected StateCommand(RxBLService service) : base(service) + protected StateCommand(RxBLService service, bool independent) : base(service, independent) { } @@ -114,9 +117,9 @@ public void Execute(Action changeCallback) } } - public static IStateCommand Create(RxBLService service) + public static IStateCommand Create(RxBLService service, bool independent) { - return new StateCommand(service); + return new StateCommand(service, independent); } } @@ -127,7 +130,7 @@ public class StateCommandAsync : StateCommand, IStateCommandAsync public CancellationToken CancellationToken { get; private set; } public Guid? ChangeCallerID { get; private set; } - protected StateCommandAsync(RxBLService service, bool canCancel) : base(service) + protected StateCommandAsync(RxBLService service, bool canCancel, bool independent) : base(service, independent) { CanCancel = canCancel; if (CanCancel) @@ -182,9 +185,9 @@ private void ResetCancellationToken() } } - public static IStateCommandAsync Create(RxBLService service, bool canCancel) + public static IStateCommandAsync Create(RxBLService service, bool canCancel, bool independent) { - return new StateCommandAsync(service, canCancel); + return new StateCommandAsync(service, canCancel, independent); } } @@ -195,8 +198,8 @@ public class StateGroupBase : StateBase, IStateGroupBase private readonly T[] _items; - protected StateGroupBase(RxBLService service, T? value, T[] items) : - base(service) + protected StateGroupBase(RxBLService service, T? value, T[] items, bool independent) : + base(service, independent) { Value = value; _items = items; @@ -216,8 +219,8 @@ public bool HasValue() public class StateGroup : StateGroupBase, IStateGroup { - protected StateGroup(RxBLService service, T? value, T[] items) : - base(service, value, items) + protected StateGroup(RxBLService service, T? value, T[] items, bool independent) : + base(service, value, items, independent) { } @@ -240,16 +243,16 @@ public void ChangeValue(T value, Action? changingCallback) } } - public static IStateGroup Create(RxBLService service, T[] items, T? value = default) + public static IStateGroup Create(RxBLService service, T[] items, T? value, bool independent) { - return new StateGroup(service, value, items); + return new StateGroup(service, value, items, independent); } } public class StateGroupAsync : StateGroupBase, IStateGroupAsync { - protected StateGroupAsync(RxBLService service, T? value, T[] items) : - base(service, value, items) + protected StateGroupAsync(RxBLService service, T? value, T[] items, bool independent) : + base(service, value, items, independent) { } @@ -273,9 +276,9 @@ public async Task ChangeValueAsync(T value, Func? changingCallbackAs } } - public static IStateGroupAsync Create(RxBLService service, T[] items, T? value = default) + public static IStateGroupAsync Create(RxBLService service, T[] items, T? value, bool independent) { - return new StateGroupAsync(service, value, items); + return new StateGroupAsync(service, value, items, independent); } } } \ No newline at end of file diff --git a/RxBlazorLightCore/RxBlazorLightCore.csproj.DotSettings b/RxBlazorLightCore/RxBlazorLightCore.csproj.DotSettings deleted file mode 100644 index 21158ca..0000000 --- a/RxBlazorLightCore/RxBlazorLightCore.csproj.DotSettings +++ /dev/null @@ -1,2 +0,0 @@ - - True \ No newline at end of file diff --git a/RxMudBlazorLight/ButtonBase/ButtonBaseRx.cs b/RxMudBlazorLight/ButtonBase/ButtonBaseRx.cs index 595e55e..7f52cbb 100644 --- a/RxMudBlazorLight/ButtonBase/ButtonBaseRx.cs +++ b/RxMudBlazorLight/ButtonBase/ButtonBaseRx.cs @@ -2,7 +2,6 @@ using MudBlazor; using RxBlazorLightCore; using RxMudBlazorLight.Extensions; -using System.Reflection.Emit; namespace RxMudBlazorLight.ButtonBase { diff --git a/RxMudBlazorLight/ButtonBase/ButtonRx.cs b/RxMudBlazorLight/ButtonBase/ButtonRx.cs index 62a4a1a..0f21951 100644 --- a/RxMudBlazorLight/ButtonBase/ButtonRx.cs +++ b/RxMudBlazorLight/ButtonBase/ButtonRx.cs @@ -38,9 +38,9 @@ public void SetParameter(IStateCommand stateCommand, Action executeCallback, Fun } OnClick = EventCallback.Factory.Create(this, () => ExecuteStateCommand(stateCommand, executeCallback)); - OnTouch = EventCallback.Factory.Create(this, () => ExecuteStateCommand(stateCommand, executeCallback)); + OnTouch = EventCallback.Factory.Create(this, () => stateCommand.Execute(executeCallback)); - Disabled = stateCommand.Changing() || (canChangeCallback is not null && !canChangeCallback()); + Disabled = stateCommand.Disabled || (canChangeCallback is not null && !canChangeCallback()); } private async Task ExecuteStateCommand(IStateCommand stateCommand, Action executeCallback) @@ -111,7 +111,7 @@ public void SetParameter(IStateCommandAsync stateCommand, Func(this, () => ExecuteStateCommandAsync(stateCommand, executeAsyncCallback, deferredNotification)); - Disabled = canChangeCallback is not null && !canChangeCallback(); + Disabled = stateCommand.Disabled || (canChangeCallback is not null && !canChangeCallback()); } OnClick ??= EventCallback.Factory.Create(this, _ => { }); diff --git a/RxMudBlazorLight/Dialogs/DialogAsyncRx.razor.cs b/RxMudBlazorLight/Dialogs/DialogAsyncRx.razor.cs index 680e72e..15caea4 100644 --- a/RxMudBlazorLight/Dialogs/DialogAsyncRx.razor.cs +++ b/RxMudBlazorLight/Dialogs/DialogAsyncRx.razor.cs @@ -95,7 +95,7 @@ private void Cancel() } } - protected override void ServiceStateHasChanged(ServiceChangeReason cr) + protected override void OnServiceStateHasChanged(ServiceChangeReason cr) { if (cr.Reason is ChangeReason.STATE && _buttonRef is not null && cr.ID == _buttonRef.StateCommand.ID) { diff --git a/RxMudBlazorLight/Dialogs/DialogRx.razor.cs b/RxMudBlazorLight/Dialogs/DialogRx.razor.cs index 16ec54b..5baf6bc 100644 --- a/RxMudBlazorLight/Dialogs/DialogRx.razor.cs +++ b/RxMudBlazorLight/Dialogs/DialogRx.razor.cs @@ -83,7 +83,7 @@ private void Cancel() } } - protected override void ServiceStateHasChanged(ServiceChangeReason cr) + protected override void OnServiceStateHasChanged(ServiceChangeReason cr) { if (cr.Reason is ChangeReason.STATE && _buttonRef is not null && cr.ID == _buttonRef.StateCommand.ID) { diff --git a/RxMudBlazorLight/Inputs/MudAutocompleteRx.razor b/RxMudBlazorLight/Inputs/MudAutocompleteRx.razor index 8d9ba96..afb2e07 100644 --- a/RxMudBlazorLight/Inputs/MudAutocompleteRx.razor +++ b/RxMudBlazorLight/Inputs/MudAutocompleteRx.razor @@ -8,7 +8,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } private RenderFragment RenderBase() => builder => base.BuildRenderTree(builder); @@ -24,7 +24,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Value = State.Value; Text = Value?.ToString(); if (Validation is Func validate) diff --git a/RxMudBlazorLight/Inputs/MudCheckBoxRx.razor b/RxMudBlazorLight/Inputs/MudCheckBoxRx.razor index c784aba..70d40dc 100644 --- a/RxMudBlazorLight/Inputs/MudCheckBoxRx.razor +++ b/RxMudBlazorLight/Inputs/MudCheckBoxRx.razor @@ -7,7 +7,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } private RenderFragment RenderBase() => builder => base.BuildRenderTree(builder); @@ -23,7 +23,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Value = State.Value; if (Validation is Func validate) { diff --git a/RxMudBlazorLight/Inputs/MudDatePickerRx.razor b/RxMudBlazorLight/Inputs/MudDatePickerRx.razor index 624edb6..b3450b4 100644 --- a/RxMudBlazorLight/Inputs/MudDatePickerRx.razor +++ b/RxMudBlazorLight/Inputs/MudDatePickerRx.razor @@ -7,7 +7,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } private RenderFragment RenderBase() => builder => base.BuildRenderTree(builder); @@ -26,7 +26,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Date = State.Value; if (Validation is Func validate) { diff --git a/RxMudBlazorLight/Inputs/MudNumericFieldRx.razor b/RxMudBlazorLight/Inputs/MudNumericFieldRx.razor index 74fc5d4..1885560 100644 --- a/RxMudBlazorLight/Inputs/MudNumericFieldRx.razor +++ b/RxMudBlazorLight/Inputs/MudNumericFieldRx.razor @@ -8,7 +8,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } private RenderFragment RenderBase() => builder => base.BuildRenderTree(builder); @@ -24,7 +24,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Value = State.Value; Text = Value?.ToString(); if (Validation is Func validate) diff --git a/RxMudBlazorLight/Inputs/MudRatingRx.razor b/RxMudBlazorLight/Inputs/MudRatingRx.razor index 1cc1560..4ab2f05 100644 --- a/RxMudBlazorLight/Inputs/MudRatingRx.razor +++ b/RxMudBlazorLight/Inputs/MudRatingRx.razor @@ -7,7 +7,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } private RenderFragment RenderBase() => builder => base.BuildRenderTree(builder); @@ -23,7 +23,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); SelectedValue = State.Value; base.OnParametersSet(); diff --git a/RxMudBlazorLight/Inputs/MudSliderRx.razor b/RxMudBlazorLight/Inputs/MudSliderRx.razor index 5b0be5d..585473a 100644 --- a/RxMudBlazorLight/Inputs/MudSliderRx.razor +++ b/RxMudBlazorLight/Inputs/MudSliderRx.razor @@ -8,7 +8,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } private RenderFragment RenderBase() => builder => base.BuildRenderTree(builder); @@ -24,7 +24,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Value = State.Value; base.OnParametersSet(); diff --git a/RxMudBlazorLight/Inputs/MudSwitchRx.razor b/RxMudBlazorLight/Inputs/MudSwitchRx.razor index 435c0b8..8397ec3 100644 --- a/RxMudBlazorLight/Inputs/MudSwitchRx.razor +++ b/RxMudBlazorLight/Inputs/MudSwitchRx.razor @@ -7,7 +7,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } private RenderFragment RenderBase() => builder => base.BuildRenderTree(builder); @@ -23,7 +23,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Value = State.Value; if (Validation is Func validate) { diff --git a/RxMudBlazorLight/Inputs/MudTextFieldRx.razor b/RxMudBlazorLight/Inputs/MudTextFieldRx.razor index d8e1c7c..89aa0a9 100644 --- a/RxMudBlazorLight/Inputs/MudTextFieldRx.razor +++ b/RxMudBlazorLight/Inputs/MudTextFieldRx.razor @@ -8,7 +8,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } private RenderFragment RenderBase() => builder => base.BuildRenderTree(builder); @@ -24,7 +24,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Value = State.Value; Text = Value?.ToString(); if (Validation is Func validate) diff --git a/RxMudBlazorLight/Inputs/MudTimePickerRx.razor b/RxMudBlazorLight/Inputs/MudTimePickerRx.razor index 0eddad8..559b8df 100644 --- a/RxMudBlazorLight/Inputs/MudTimePickerRx.razor +++ b/RxMudBlazorLight/Inputs/MudTimePickerRx.razor @@ -7,7 +7,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } private RenderFragment RenderBase() => builder => base.BuildRenderTree(builder); @@ -26,7 +26,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Time = State.Value; if (Validation is Func validate) { diff --git a/RxMudBlazorLight/Inputs/Radio/MudRadioGroupAsyncRx.razor b/RxMudBlazorLight/Inputs/Radio/MudRadioGroupAsyncRx.razor index b6be8e8..5d79ee0 100644 --- a/RxMudBlazorLight/Inputs/Radio/MudRadioGroupAsyncRx.razor +++ b/RxMudBlazorLight/Inputs/Radio/MudRadioGroupAsyncRx.razor @@ -74,7 +74,7 @@ { if (StateGroupAsync.HasValue()) { - Disabled = (CanChangeCallback is not null && !CanChangeCallback()) || StateGroupAsync.Changing(); + Disabled = StateGroupAsync.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); if (StateGroupAsync.Done()) { diff --git a/RxMudBlazorLight/Inputs/Radio/MudRadioGroupRx.razor b/RxMudBlazorLight/Inputs/Radio/MudRadioGroupRx.razor index ce817b1..941c6fb 100644 --- a/RxMudBlazorLight/Inputs/Radio/MudRadioGroupRx.razor +++ b/RxMudBlazorLight/Inputs/Radio/MudRadioGroupRx.razor @@ -74,7 +74,7 @@ { if (StateGroup.HasValue()) { - Disabled = (CanChangeCallback is not null && !CanChangeCallback()); + Disabled = StateGroup.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Value = StateGroup.Value; if (Validation is Func validate) diff --git a/RxMudBlazorLight/Inputs/Select/MudSelectAsyncRx.razor b/RxMudBlazorLight/Inputs/Select/MudSelectAsyncRx.razor index 5636dda..9f834d8 100644 --- a/RxMudBlazorLight/Inputs/Select/MudSelectAsyncRx.razor +++ b/RxMudBlazorLight/Inputs/Select/MudSelectAsyncRx.razor @@ -65,7 +65,7 @@ { if (StateGroupAsync.HasValue()) { - Disabled = (CanChangeCallback is not null && !CanChangeCallback()) || StateGroupAsync.Changing(); + Disabled = StateGroupAsync.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); if (StateGroupAsync.Done()) { diff --git a/RxMudBlazorLight/Inputs/Select/MudSelectRx.razor b/RxMudBlazorLight/Inputs/Select/MudSelectRx.razor index 23a5359..369cde6 100644 --- a/RxMudBlazorLight/Inputs/Select/MudSelectRx.razor +++ b/RxMudBlazorLight/Inputs/Select/MudSelectRx.razor @@ -65,7 +65,7 @@ { if (StateGroup.HasValue()) { - Disabled = (CanChangeCallback is not null && !CanChangeCallback()); + Disabled = StateGroup.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Value = StateGroup.Value; Text = Value?.ToString(); diff --git a/RxMudBlazorLight/ToggleIconButtons/MudToggleIconButtonRx.razor b/RxMudBlazorLight/ToggleIconButtons/MudToggleIconButtonRx.razor index 4da558c..f97b216 100644 --- a/RxMudBlazorLight/ToggleIconButtons/MudToggleIconButtonRx.razor +++ b/RxMudBlazorLight/ToggleIconButtons/MudToggleIconButtonRx.razor @@ -7,7 +7,7 @@ public required IState State { get; init; } [Parameter] - public Func? CanChangeCallback { get; init; } + public Func? CanChangeCallback { get; init; } [Parameter] public Func>? ConfirmExecution { get; set; } @@ -32,7 +32,7 @@ protected override void OnParametersSet() { - Disabled = (CanChangeCallback is not null && !CanChangeCallback(State.Value)); + Disabled = State.Disabled || (CanChangeCallback is not null && !CanChangeCallback()); Toggled = State.Value; base.OnParametersSet(); diff --git a/RxMudBlazorLightTestBase/Components/InputTest.razor b/RxMudBlazorLightTestBase/Components/InputTest.razor index ce8d410..b833758 100644 --- a/RxMudBlazorLightTestBase/Components/InputTest.razor +++ b/RxMudBlazorLightTestBase/Components/InputTest.razor @@ -42,7 +42,7 @@ ToggledIcon="@Icons.Material.Outlined.CheckCircle" ToggledColor="@Color.Success" ToggledTitle="On" /> CanIncrementCheck is @(Service.CanIncrementCheck.Value ? "On" : "Off") - Service.NumericState.Value < 20)>IncrementValue + Service.NumericState.Value < 20)>IncrementValue Add 5 Add Count @@ -82,7 +82,7 @@ SetImageSource(); } - protected override async Task ServiceStateHasChangedAsync(ServiceChangeReason cr) + protected override async Task OnServiceStateHasChangedAsync(ServiceChangeReason cr) { if (cr.ID == Service.CanIncrementCheck.ID) { diff --git a/RxMudBlazorLightTestBase/Components/TestPlayground.razor b/RxMudBlazorLightTestBase/Components/TestPlayground.razor index dc19eb1..2e79c04 100644 --- a/RxMudBlazorLightTestBase/Components/TestPlayground.razor +++ b/RxMudBlazorLightTestBase/Components/TestPlayground.razor @@ -31,7 +31,7 @@ private long _countStateChanges = 0; - protected override void ServiceStateHasChanged(ServiceChangeReason cr) + protected override void OnServiceStateHasChanged(ServiceChangeReason cr) { if (cr.ID == Service.Command.ID && Service.Command.Changed()) { diff --git a/RxMudBlazorLightTestBase/Service/CrudService.cs b/RxMudBlazorLightTestBase/Service/CrudService.cs index b108275..db37c95 100644 --- a/RxMudBlazorLightTestBase/Service/CrudService.cs +++ b/RxMudBlazorLightTestBase/Service/CrudService.cs @@ -78,12 +78,12 @@ public bool CanSubmit() (Text.Value != item?.Text || dateNew != dateItem); } - public Func CanUpdateText => _ => + public Func CanUpdateText => () => { return service.CanUpdateText; }; - public Func CanUpdateDueDate => _ => + public Func CanUpdateDueDate => () => { return service.CanUpdateDueDate; }; @@ -106,7 +106,7 @@ public bool CanSubmit() return new("DueDate can not be in the past!", dateNew < dateNowNS); }; - public Func CanUpdateTime => _ => + public Func CanUpdateTime => () => { return service.CanUpdateDueDate; }; diff --git a/RxMudBlazorLightTestBase/Service/TestService.State.cs b/RxMudBlazorLightTestBase/Service/TestService.State.cs index 8194b94..7cd6757 100644 --- a/RxMudBlazorLightTestBase/Service/TestService.State.cs +++ b/RxMudBlazorLightTestBase/Service/TestService.State.cs @@ -53,7 +53,7 @@ public bool ColorDisabled(int index) return index == 1 && CanIncrementCheck.Value; } - public bool AddModeCanChange(bool _) + public bool AddModeCanChange() { return !Command.Changing() && !CommandAsync.Changing(); }