Skip to content

Commit

Permalink
Merge pull request #535 from marner2/feature/use_initialModel_for_ini…
Browse files Browse the repository at this point in the history
…tialize

Don't call getCurrentModel on initialization
  • Loading branch information
TysonMN committed Oct 16, 2022
2 parents 65c9317 + cc0bb26 commit d1e978a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/Elmish.WPF.Tests/BindingVmHelpersTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,20 @@ let name = "name"
let noGetSelectedItemCall _ = failwith "Should not call get selected item"


module Initialize =

[<Fact>]
let ``Initialize doesn't call getCurrentModel`` () =
let binding =
BindingData.OneWay.id<string, string>
|> 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>) =
Expand Down
2 changes: 1 addition & 1 deletion src/Elmish.WPF/BindingVmHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d1e978a

Please sign in to comment.