diff --git a/src/Samples/SubModelStatic.Core/Program.fs b/src/Samples/SubModelStatic.Core/Program.fs index 70f29573..bf13360b 100644 --- a/src/Samples/SubModelStatic.Core/Program.fs +++ b/src/Samples/SubModelStatic.Core/Program.fs @@ -11,7 +11,8 @@ module Counter = type Model = { Count: int - StepSize: int } + StepSize: int + History: (int * int) list } type Msg = | Increment @@ -21,21 +22,22 @@ module Counter = let init = { Count = 0 - StepSize = 1 } + StepSize = 1 + History = [] } let canReset = (<>) init let update msg m = match msg with - | Increment -> { m with Count = m.Count + m.StepSize } - | Decrement -> { m with Count = m.Count - m.StepSize } + | Increment -> { m with Count = m.Count + m.StepSize; History = (m.Count, m.History.Length) :: m.History } + | Decrement -> { m with Count = m.Count - m.StepSize; History = (m.Count, m.History.Length) :: m.History } | SetStepSize x -> { m with StepSize = x } | Reset -> init type [] CounterViewModel (args) = inherit ViewModelBase(args) - new() = CounterViewModel(Counter.init |> ViewModelArgs.simple) + new() = CounterViewModel({ Counter.init with History = [ (3,1); (0,0) ] } |> ViewModelArgs.simple) member _.StepSize with get() = base.Get() (Binding.OneWayT.id >> Binding.addLazy (=) >> Binding.mapModel (fun m -> m.StepSize)) @@ -44,6 +46,7 @@ type [] CounterViewModel (args) = member _.Increment = base.Get() (Binding.CmdT.setAlways Counter.Increment) member _.Decrement = base.Get() (Binding.CmdT.setAlways Counter.Decrement) member _.Reset = base.Get() (Binding.CmdT.set Counter.canReset Counter.Reset) + member _.History = base.Get() (Binding.OneWaySeqT.id (=) snd >> Binding.mapModel (fun m -> m.History)) module Clock = diff --git a/src/Samples/SubModelStatic/Counter.xaml b/src/Samples/SubModelStatic/Counter.xaml index 2fa11674..5551966d 100644 --- a/src/Samples/SubModelStatic/Counter.xaml +++ b/src/Samples/SubModelStatic/Counter.xaml @@ -6,12 +6,37 @@ xmlns:vm="clr-namespace:Elmish.WPF.Samples.SubModelStatic;assembly=SubModelStatic.Core" mc:Ignorable="d" d:DataContext="{d:DesignInstance Type=vm:CounterViewModel, IsDesignTimeCreatable=True}"> - - -