From 539ff6572ef1dc6a8fe0be1e4b1148f525714111 Mon Sep 17 00:00:00 2001 From: Joshua Marner Date: Tue, 4 Jun 2024 14:11:00 -0500 Subject: [PATCH 1/3] Add opt and vopt helper functions for OneWayT, TwoWayT and OneWayToSourceT --- src/Elmish.WPF/Binding.fs | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/src/Elmish.WPF/Binding.fs b/src/Elmish.WPF/Binding.fs index ab30862e..25b12b4b 100644 --- a/src/Elmish.WPF/Binding.fs +++ b/src/Elmish.WPF/Binding.fs @@ -106,6 +106,36 @@ module Binding = OneWay.id |> createBindingT + /// Creates a one-way binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let opt x : Binding<'a option, 'msg, System.Nullable<'a>> = + x + |> id + |> mapModel Option.toNullable + + /// Creates a one-way binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let vopt x : Binding<'a voption, 'msg, System.Nullable<'a>> = + x + |> id + |> mapModel ValueOption.toNullable + + /// Creates a one-way binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let optobj<'a, 'msg when 'a : null> : string -> Binding<'a option, 'msg, 'a> = + id<'a, 'msg> + >> mapModel Option.toObj + + /// Creates a one-way binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let voptobj<'a, 'msg when 'a : null> : string -> Binding<'a voption, 'msg, 'a> = + id<'a, 'msg> + >> mapModel ValueOption.toObj + /// /// Strongly-typed bindings that update the model from the view. /// @@ -116,6 +146,36 @@ module Binding = OneWayToSource.id |> createBindingT + /// Creates a one-way-to-source binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let optobj<'a, 'model when 'a : null> : string -> Binding<'model, 'a option, 'a> = + id<'model, 'a> + >> mapMsg Option.ofObj + + /// Creates a one-way-to-source binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let voptobj<'a, 'model when 'a : null> : string -> Binding<'model, 'a voption, 'a> = + id<'model, 'a> + >> mapMsg ValueOption.ofObj + + /// Creates a one-way-to-source binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let opt x : Binding<'model, 'a option, System.Nullable<'a>> = + x + |> id + |> mapMsg Option.ofNullable + + /// Creates a one-way-to-source binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let vopt x : Binding<'model, 'a voption, System.Nullable<'a>> = + x + |> id + |> mapMsg ValueOption.ofNullable + /// /// Strongly-typed bindings that update both ways /// @@ -125,6 +185,40 @@ module Binding = let id<'a> : string -> Binding<'a, 'a, 'a> = TwoWay.id |> createBindingT + + /// Creates a two-way binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let opt x : Binding<'a option, 'a option, System.Nullable<'a>> = + x + |> id + |> mapMsg Option.ofNullable + |> mapModel Option.toNullable + + /// Creates a two-way binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let vopt x : Binding<'a voption, 'a voption, System.Nullable<'a>> = + x + |> id + |> mapMsg ValueOption.ofNullable + |> mapModel ValueOption.toNullable + + /// Creates a two-way binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let optobj<'a when 'a : null> : string -> Binding<'a option, 'a option, 'a> = + id<'a> + >> mapModel Option.toObj + >> mapMsg Option.ofObj + + /// Creates a two-way binding to an optional value. The binding + /// automatically converts between a missing value in the model and + /// a null value in the view. + let voptobj<'a when 'a : null> : string -> Binding<'a voption, 'a voption, 'a> = + id<'a> + >> mapMsg ValueOption.ofObj + >> mapModel ValueOption.toObj /// /// The strongly-typed counterpart of Binding.oneWaySeq with parameter getId. From 18b9ae97e98e7effce9d50e8996f35df7fce364c Mon Sep 17 00:00:00 2001 From: Joshua Marner Date: Tue, 4 Jun 2024 14:11:10 -0500 Subject: [PATCH 2/3] Fix typos --- src/Elmish.WPF/Binding.fs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Elmish.WPF/Binding.fs b/src/Elmish.WPF/Binding.fs index 25b12b4b..c95c56d9 100644 --- a/src/Elmish.WPF/Binding.fs +++ b/src/Elmish.WPF/Binding.fs @@ -359,7 +359,7 @@ module Binding = TwoWay.id |> createBinding - /// Creates a one-way-to-source binding to an optional value. The binding + /// Creates a two-way binding to an optional value. The binding /// automatically converts between a missing value in the model and /// a null value in the view. let vopt<'a> : string -> Binding<'a voption, 'a voption> = @@ -367,7 +367,7 @@ module Binding = >> mapModel ValueOption.box >> mapMsg ValueOption.unbox - /// Creates a one-way-to-source binding to an optional value. The binding + /// Creates a two-way binding to an optional value. The binding /// automatically converts between a missing value in the model and /// a null value in the view. let opt<'a> : string -> Binding<'a option, 'a option> = From e74094cbf846a54b1a9c38d95b7f7e20ccc695bf Mon Sep 17 00:00:00 2001 From: Joshua Marner Date: Tue, 4 Jun 2024 14:11:55 -0500 Subject: [PATCH 3/3] Bump version --- RELEASE_NOTES.md | 6 ++++++ src/Elmish.WPF/Elmish.WPF.fsproj | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index dcd6c870..30f1031b 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,9 @@ +#### 4.0.0-beta-55 +* Add TwoWayT bindings for workflows that reuse bindings. +* Add OneWayToSeqT bindings. +* Add vopt and opt bindings for OneWayT, OneWayToSourceT, and TwoWayT bindings. +* Add .NET 8 target and remove .NET Core 3.1 support + #### 4.0.0-beta-54 * Added the Readme file to the generated nuspec file so that it shows up on nuget.org. * Added some debug logs to the performance logger at the top level. diff --git a/src/Elmish.WPF/Elmish.WPF.fsproj b/src/Elmish.WPF/Elmish.WPF.fsproj index 9146b267..371935dc 100644 --- a/src/Elmish.WPF/Elmish.WPF.fsproj +++ b/src/Elmish.WPF/Elmish.WPF.fsproj @@ -18,7 +18,7 @@ https://github.com/elmish/Elmish.WPF WPF F# fsharp Elmish Elm elmish-wpf-logo-128x128.png - 4.0.0-beta-54 + 4.0.0-beta-55 https://github.com/elmish/Elmish.WPF/blob/master/RELEASE_NOTES.md README.md