diff --git a/src/Elmish.WPF/Binding.fs b/src/Elmish.WPF/Binding.fs index 33d17008..d3c07694 100644 --- a/src/Elmish.WPF/Binding.fs +++ b/src/Elmish.WPF/Binding.fs @@ -116,6 +116,16 @@ module Binding = OneWayToSource.id |> createBindingT + /// + /// Strongly-typed bindings that update both ways + /// + module TwoWayT = + + /// Elemental instance of a two-way binding. + let id<'a> : string -> Binding<'a, 'a, 'a> = + TwoWay.id + |> createBindingT + /// /// Strongly-typed bindings that dispatch messages from the view. /// diff --git a/src/Samples/SubModelStatic.Core/Program.fs b/src/Samples/SubModelStatic.Core/Program.fs index 70f29573..297e7d08 100644 --- a/src/Samples/SubModelStatic.Core/Program.fs +++ b/src/Samples/SubModelStatic.Core/Program.fs @@ -35,11 +35,17 @@ module Counter = type [] CounterViewModel (args) = inherit ViewModelBase(args) + let stepSizeBinding = + Binding.TwoWayT.id + >> Binding.addLazy (=) + >> Binding.mapModel (fun (m: Counter.Model) -> m.StepSize) + >> Binding.mapMsg Counter.Msg.SetStepSize + new() = CounterViewModel(Counter.init |> ViewModelArgs.simple) member _.StepSize - with get() = base.Get() (Binding.OneWayT.id >> Binding.addLazy (=) >> Binding.mapModel (fun m -> m.StepSize)) - and set(v) = base.Set(v) (Binding.OneWayToSourceT.id >> Binding.mapMsg Counter.Msg.SetStepSize) + with get() = base.Get() stepSizeBinding + and set(v) = base.Set(v) stepSizeBinding member _.CounterValue = base.Get() (Binding.OneWayT.id >> Binding.addLazy (=) >> Binding.mapModel (fun m -> m.Count)) member _.Increment = base.Get() (Binding.CmdT.setAlways Counter.Increment) member _.Decrement = base.Get() (Binding.CmdT.setAlways Counter.Decrement)