diff --git a/src/Elmish.WPF/Binding.fs b/src/Elmish.WPF/Binding.fs index 2abc6e1a..3116be33 100644 --- a/src/Elmish.WPF/Binding.fs +++ b/src/Elmish.WPF/Binding.fs @@ -1,4 +1,4 @@ -namespace Elmish.WPF +namespace Elmish.WPF open System.Collections.Generic open System.Collections.ObjectModel @@ -903,16 +903,21 @@ module internal Helpers = [] type Binding private () = + + static member private defaultOneWayBinding () : string -> Binding<'model, 'msg> = + { Get = id } + |> OneWayData.box + |> OneWayData + |> createBinding + /// Creates a one-way binding. /// Gets the value from the model. static member oneWay (get: 'model -> 'a) : string -> Binding<'model, 'msg> = - { Get = get } - |> OneWayData.box - |> OneWayData - |> createBinding + Binding.defaultOneWayBinding () + >> Binding.mapModel get /// @@ -925,10 +930,8 @@ type Binding private () = static member oneWayOpt (get: 'model -> 'a option) : string -> Binding<'model, 'msg> = - { Get = get } - |> OneWayData.boxOpt - |> OneWayData - |> createBinding + Binding.defaultOneWayBinding () + >> Binding.mapModel (get >> Option.toObj) /// @@ -941,10 +944,8 @@ type Binding private () = static member oneWayOpt (get: 'model -> 'a voption) : string -> Binding<'model, 'msg> = - { Get = get } - |> OneWayData.boxVOpt - |> OneWayData - |> createBinding + Binding.defaultOneWayBinding () + >> Binding.mapModel (get >> ValueOption.toObj) ///