Skip to content

Commit

Permalink
this order passes the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyson Williams committed Dec 7, 2020
1 parent 838bd02 commit c4e9e7f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
6 changes: 3 additions & 3 deletions src/Elmish.WPF.Tests/BindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,7 @@ module subModel =
Property.check <| property {
let! m = GenX.auto<int>
let! x = GenX.auto<int>
let d = Binding.subModel(fail, fail) |> getSubModelData
let d = Binding.subModel(id, fail) |> getSubModelData
test <@ d.ToMsg m (box x) = x @>
}

Expand Down Expand Up @@ -3044,7 +3044,7 @@ module subModel =
let! x = GenX.auto<int>

let toMsg = string<int>
let d = Binding.subModel(fail, toMsg, fail) |> getSubModelData
let d = Binding.subModel(id, toMsg, fail) |> getSubModelData

test <@ d.ToMsg m (box x) = toMsg x @>
}
Expand Down Expand Up @@ -3088,7 +3088,7 @@ module subModel =
let! x = GenX.auto<int>

let toMsg = string<int>
let d = Binding.subModel(fail, fail, toMsg, fail) |> getSubModelData
let d = Binding.subModel(id, id, toMsg, fail) |> getSubModelData

test <@ d.ToMsg m (box x) = toMsg x @>
}
Expand Down
37 changes: 23 additions & 14 deletions src/Elmish.WPF/Binding.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,18 @@ type Binding private () =
|> createBinding


static member subModel
(bindings: unit -> Binding<'model, 'msg> list)
: string -> Binding<'model, 'msg> =
{ GetModel = ValueSome
GetBindings = bindings
ToMsg = fun _ -> id
Sticky = false }
|> SubModelData.box
|> SubModelData
|> createBinding


/// <summary>
/// Creates a binding to a sub-model/component that has its own bindings.
/// You typically bind this to the <c>DataContext</c> of a
Expand All @@ -1577,13 +1589,9 @@ type Binding private () =
(getSubModel: 'model -> 'subModel,
bindings: unit -> Binding<'model * 'subModel, 'msg> list)
: string -> Binding<'model, 'msg> =
{ GetModel = fun m -> (m, getSubModel m) |> ValueSome
GetBindings = bindings
ToMsg = fun _ -> id
Sticky = false }
|> SubModelData.box
|> SubModelData
|> createBinding
bindings
|> Binding.subModel
>> Binding.mapModel (fun m -> (m, getSubModel m))


/// <summary>
Expand All @@ -1602,8 +1610,10 @@ type Binding private () =
toMsg: 'subMsg -> 'msg,
bindings: unit -> Binding<'model * 'subModel, 'subMsg> list)
: string -> Binding<'model, 'msg> =
let bindings () = bindings () |> Bindings.mapMsg toMsg
Binding.subModel(getSubModel, bindings)
bindings
|> Binding.subModel
>> Binding.mapModel (fun m -> (m, getSubModel m))
>> Binding.mapMsg toMsg


/// <summary>
Expand All @@ -1626,11 +1636,10 @@ type Binding private () =
toMsg: 'bindingMsg -> 'msg,
bindings: unit -> Binding<'bindingModel, 'bindingMsg> list)
: string -> Binding<'model, 'msg> =
let bindings () =
bindings ()
|> Bindings.mapMsg toMsg
|> Bindings.mapModel toBindingModel
Binding.subModel(getSubModel, bindings)
bindings
|> Binding.subModel
>> Binding.mapModel (fun m -> (m, getSubModel m) |> toBindingModel)
>> Binding.mapMsg toMsg


/// <summary>
Expand Down

0 comments on commit c4e9e7f

Please sign in to comment.