-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
Current component record implementations does not implement optional fields as optional.
- This force long winded code.
- Puts it on the user to specify a default value for optional fields.
- Is inconsistent with implementations for Python, Julia, R and MATLAB (as far as I can tell).
- Not clear from the code which fields are optional.
Current state
Taking DropdownOption
as an example.
The fields are described as:
- Label: string | number (required)
- Value: string | number (required)
- Disabled: boolean (optional)
- Title: string (optional)
But is implemented as:
type DropdownOption =
{
Label:IConvertible
Value:IConvertible
Disabled:bool // Optional - but must provide a value
Title:string // Optional - but must provide a value
}
// Both optional arguments require a value
static member create label value disabled title = {Label=label; Value=value; Disabled=disabled; Title=title}
Usage:
Dropdown.Attr.options [
// Forced to provide a default value
DropdownOption.create "Population" "pop" false "Population"
DropdownOption.create "Life Expectancy" "lifeExp" false "Life Expectancy"
DropdownOption.create "GDP per Capita" "gdpPercap" false "GDP per Capita"
]
Proposal
- Make optional fields optional.
type DropdownOption =
{
Label: IConvertible
Value: IConvertible
Disabled: bool option // Clearly optional
Title: string option // Clearly optional
}
create
method making use of tuples with optional arguments (also allows overloading where curry does not).
static member create (label, value, ?disabled, ?title) = { Label=label; Value=value; Disabled=disabled; Title=title }
Usage:
Dropdown.Attr.options [
DropdownOption.create ("Population", "pop")
DropdownOption.create ("Life Expectancy", "lifeExp", title = "My Life Expectancy")
DropdownOption.create ("GDP per Capita", "gdpPercap", true)
]
Example convert
method:
static member convert this =
box {|
label = this.Label
value = this.Value
disabled = match this.Disabled with Some isDisabled -> box isDisabled | None -> null
title = match this.Title with Some title -> box title | None -> null
|}
Metadata
Metadata
Assignees
Labels
No labels