From f5375a8d40f0c9952d0c5e35c494252653f839fb Mon Sep 17 00:00:00 2001 From: Joshua Marner Date: Sat, 15 Oct 2022 19:24:36 -0500 Subject: [PATCH 1/2] Don't call getCurrentModel on initialization (it always returns same thing) --- src/Elmish.WPF/BindingVmHelpers.fs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Elmish.WPF/BindingVmHelpers.fs b/src/Elmish.WPF/BindingVmHelpers.fs index 2826289a..413712c9 100644 --- a/src/Elmish.WPF/BindingVmHelpers.fs +++ b/src/Elmish.WPF/BindingVmHelpers.fs @@ -438,7 +438,7 @@ type Initialize<'t> | ValidationData d -> let d = d |> BindingData.Validation.measureFunctions measure let! b = this.Recursive(initialModel, dispatch, getCurrentModel, d.BindingData) - return b.AddValidation (getCurrentModel ()) d.Validate + return b.AddValidation initialModel d.Validate | LazyData d -> let initialModel' : obj = d.Get initialModel let getCurrentModel' : unit -> obj = getCurrentModel >> d.Get From cc0bb26a7ac69cf0ba749720a590653ce811b50a Mon Sep 17 00:00:00 2001 From: Joshua Marner Date: Sat, 15 Oct 2022 19:45:49 -0500 Subject: [PATCH 2/2] Add test to verify that this is true --- src/Elmish.WPF.Tests/BindingVmHelpersTests.fs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Elmish.WPF.Tests/BindingVmHelpersTests.fs b/src/Elmish.WPF.Tests/BindingVmHelpersTests.fs index 6ba809b2..f59d9814 100644 --- a/src/Elmish.WPF.Tests/BindingVmHelpersTests.fs +++ b/src/Elmish.WPF.Tests/BindingVmHelpersTests.fs @@ -15,6 +15,20 @@ let name = "name" let noGetSelectedItemCall _ = failwith "Should not call get selected item" +module Initialize = + + [] + let ``Initialize doesn't call getCurrentModel`` () = + let binding = + BindingData.OneWay.id + |> BindingData.addValidation List.singleton + + let vmBinding = + Initialize(LoggingViewModelArgs.none, name, noGetSelectedItemCall) + .Recursive("", ignore, (fun _ -> failwith "Should not call getCurrentModel on initialize"), binding) + + test <@ vmBinding.IsSome @> + module Get = let check<'a when 'a : equality> (g: Gen<'a>) =