From 3c476a49ee8e191bec31e89bd39edde4a5837fb3 Mon Sep 17 00:00:00 2001 From: Joshua Marner Date: Tue, 1 Oct 2024 15:48:56 -0500 Subject: [PATCH 1/3] Add test specifying feature --- src/Elmish.WPF.Tests/DynamicViewModelTests.fs | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/Elmish.WPF.Tests/DynamicViewModelTests.fs b/src/Elmish.WPF.Tests/DynamicViewModelTests.fs index baaa5bff..e54888af 100644 --- a/src/Elmish.WPF.Tests/DynamicViewModelTests.fs +++ b/src/Elmish.WPF.Tests/DynamicViewModelTests.fs @@ -844,6 +844,26 @@ module TwoWayValidate = } + [] + let ``when model is updated, should trigger NotifyPropertyChanged on HasErrors iff the value returned by validate changes`` () = + Property.check <| property { + let! name = GenX.auto + let! m1 = GenX.auto + let! m2 = GenX.auto + + let get _ = () + let set _ _ = () + let validate m = if m < 0 then ValueSome (string m) else ValueNone + + let binding = twoWayValidate name get set validate + let vm = TestVm(m1, binding) + + vm.UpdateModel m2 + + test <@ vm.NumPcTriggersFor "HasErrors" = if (validate m1 |> ValueOption.isNone) = (validate m2 |> ValueOption.isNone) then 0 else 1 @> + } + + [] let ``when validate returns ValueNone, HasErrors should return false and GetErrors should return an empty collection`` () = Property.check <| property { From 7f6b5b7c2d8a218adcab7981653634a168ab188c Mon Sep 17 00:00:00 2001 From: Joshua Marner Date: Tue, 1 Oct 2024 15:49:18 -0500 Subject: [PATCH 2/3] Notify HasErrors property when it changes --- src/Elmish.WPF/ViewModels.fs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Elmish.WPF/ViewModels.fs b/src/Elmish.WPF/ViewModels.fs index e881e6b8..e58c8f8a 100644 --- a/src/Elmish.WPF/ViewModels.fs +++ b/src/Elmish.WPF/ViewModels.fs @@ -177,8 +177,10 @@ type [] internal DynamicViewModel<'model, 'msg> member _.CurrentModel : 'model = helper.Model member _.UpdateModel (newModel: 'model) : unit = + let prevHasErrors = (helper :> INotifyDataErrorInfo).HasErrors let eventsToRaise = ViewModelHelper.getEventsToRaise newModel helper helper <- { helper with Model = newModel } + let eventsToRaise = if prevHasErrors = (helper :> INotifyDataErrorInfo).HasErrors then eventsToRaise else (PropertyChanged "HasErrors") :: eventsToRaise ViewModelHelper.raiseEvents eventsToRaise helper override _.TryGetMember (binder, result) = From bf0c2bac4ccbd65113fdf82707e5b2d900675366 Mon Sep 17 00:00:00 2001 From: Joshua Marner Date: Tue, 1 Oct 2024 15:59:52 -0500 Subject: [PATCH 3/3] Bump version --- RELEASE_NOTES.md | 3 +++ src/Elmish.WPF/Elmish.WPF.fsproj | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 30f1031b..aa03d24d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +#### 4.0.0-beta-56 +* Add NotifyPropertyChanged for the HasErrors property. + #### 4.0.0-beta-55 * Add TwoWayT bindings for workflows that reuse bindings. * Add OneWayToSeqT bindings. diff --git a/src/Elmish.WPF/Elmish.WPF.fsproj b/src/Elmish.WPF/Elmish.WPF.fsproj index 371935dc..a9053e38 100644 --- a/src/Elmish.WPF/Elmish.WPF.fsproj +++ b/src/Elmish.WPF/Elmish.WPF.fsproj @@ -18,7 +18,7 @@ https://github.com/elmish/Elmish.WPF WPF F# fsharp Elmish Elm elmish-wpf-logo-128x128.png - 4.0.0-beta-55 + 4.0.0-beta-56 https://github.com/elmish/Elmish.WPF/blob/master/RELEASE_NOTES.md README.md