Skip to content

Commit

Permalink
Add opt and vopt helper functions for OneWayT, TwoWayT and OneWayToSo…
Browse files Browse the repository at this point in the history
…urceT
  • Loading branch information
marner2 committed Apr 23, 2024
1 parent fd8a645 commit d10d737
Showing 1 changed file with 96 additions and 2 deletions.
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<'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 vopt<'a, 'msg when 'a : null> : string -> Binding<'a voption, 'msg, 'a> =
id<'a, 'msg>
>> mapModel ValueOption.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 opt2 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 vopt2 x : Binding<'a voption, 'msg, System.Nullable<'a>> =
x
|> id
|> mapModel ValueOption.toNullable

/// <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 opt<'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 vopt<'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 opt2 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 vopt2 x : Binding<'model, 'a voption, System.Nullable<'a>> =
x
|> id
|> mapMsg ValueOption.ofNullable

/// <summary>
/// Strongly-typed bindings that update both ways
/// </summary>
Expand All @@ -142,6 +202,40 @@ module Binding =
OneWaySeq.create itemEquals getId
|> 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<'a when 'a : null> : string -> Binding<'a option, 'a option, 'a> =
id<'a>

Check failure on line 209 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

This value, type or method expects 4 type parameter(s) but was given 1

Check failure on line 209 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

This value, type or method expects 4 type parameter(s) but was given 1

Check failure on line 209 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

This value, type or method expects 4 type parameter(s) but was given 1
>> 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 vopt<'a when 'a : null> : string -> Binding<'a voption, 'a voption, 'a> =
id<'a>

Check failure on line 217 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

This value, type or method expects 4 type parameter(s) but was given 1

Check failure on line 217 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

This value, type or method expects 4 type parameter(s) but was given 1

Check failure on line 217 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

This value, type or method expects 4 type parameter(s) but was given 1
>> mapMsg ValueOption.ofObj
>> mapModel ValueOption.toObj

/// 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 opt2 x : Binding<'a option, 'a option, System.Nullable<'a>> =
x
|> id
|> mapMsg Option.ofNullable

Check failure on line 227 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

Type mismatch. Expecting a� '(('a -> 'b) -> string -> Binding<'c,'d,ObservableCollection<'a>>) -> 'e' �but given a� 'Binding<'f,'g,'h> -> Binding<'f,'i,'h>' �The type '('a -> 'b) -> string -> Binding<'c,'d,ObservableCollection<'a>>' does not match the type 'Binding<'e,'f,'g>'

Check failure on line 227 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

Type mismatch. Expecting a� '(('a -> 'b) -> string -> Binding<'c,'d,ObservableCollection<'a>>) -> 'e' �but given a� 'Binding<'f,'g,'h> -> Binding<'f,'i,'h>' �The type '('a -> 'b) -> string -> Binding<'c,'d,ObservableCollection<'a>>' does not match the type 'Binding<'e,'f,'g>'

Check failure on line 227 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

Type mismatch. Expecting a� '(('a -> 'b) -> string -> Binding<'c,'d,ObservableCollection<'a>>) -> 'e' �but given a� 'Binding<'f,'g,'h> -> Binding<'f,'i,'h>' �The type '('a -> 'b) -> string -> Binding<'c,'d,ObservableCollection<'a>>' does not match the type 'Binding<'e,'f,'g>'

Check failure on line 227 in src/Elmish.WPF/Binding.fs

View workflow job for this annotation

GitHub Actions / build

Type mismatch. Expecting a� '(('a -> 'b) -> string -> Binding<'c,'d,ObservableCollection<'a>>) -> 'e' �but given a� 'Binding<'f,System.Nullable<'g>,'h> -> Binding<'f,'g option,'h>' �The type '('a -> 'b) -> string -> Binding<'c,'d,ObservableCollection<'a>>' does not match the type 'Binding<'e,System.Nullable<'f>,'g>'
|> 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 vopt2 x : Binding<'a voption, 'a voption, System.Nullable<'a>> =
x
|> id
|> mapMsg ValueOption.ofNullable
|> mapModel ValueOption.toNullable

/// <summary>
/// Strongly-typed bindings that dispatch messages from the view.
/// </summary>
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

0 comments on commit d10d737

Please sign in to comment.