Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add opt and vopt helper functions #602

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
98 changes: 96 additions & 2 deletions src/Elmish.WPF/Binding.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <c>null</c> 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 <c>null</c> 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 <c>null</c> 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 <c>null</c> value in the view.
let voptobj<'a, 'msg when 'a : null> : string -> Binding<'a voption, 'msg, 'a> =
id<'a, 'msg>
>> mapModel ValueOption.toObj

/// <summary>
/// Strongly-typed bindings that update the model from the view.
/// </summary>
Expand All @@ -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 <c>null</c> 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 <c>null</c> 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 <c>null</c> 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 <c>null</c> value in the view.
let vopt x : Binding<'model, 'a voption, System.Nullable<'a>> =
x
|> id
|> mapMsg ValueOption.ofNullable

/// <summary>
/// Strongly-typed bindings that update both ways
/// </summary>
Expand All @@ -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 <c>null</c> 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 <c>null</c> 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 <c>null</c> 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 <c>null</c> 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

/// <summary>
/// The strongly-typed counterpart of <c>Binding.oneWaySeq</c> with parameter <c>getId</c>.
Expand Down Expand Up @@ -265,15 +359,15 @@ 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 <c>null</c> value in the view.
let vopt<'a> : string -> Binding<'a voption, 'a voption> =
id<obj>
>> 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 <c>null</c> value in the view.
let opt<'a> : string -> Binding<'a option, 'a option> =
Expand Down
2 changes: 1 addition & 1 deletion src/Elmish.WPF/Elmish.WPF.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<PackageProjectUrl>https://github.com/elmish/Elmish.WPF</PackageProjectUrl>
<PackageTags>WPF F# fsharp Elmish Elm</PackageTags>
<PackageIcon>elmish-wpf-logo-128x128.png</PackageIcon>
<Version>4.0.0-beta-54</Version>
<Version>4.0.0-beta-55</Version>
<PackageReleaseNotes>https://github.com/elmish/Elmish.WPF/blob/master/RELEASE_NOTES.md</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!--Turn on warnings for unused values (arguments and let bindings) -->
Expand Down
Loading