-
Notifications
You must be signed in to change notification settings - Fork 12
Optional component record fields #29
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
Comments
This is why I agree that these records should be switched to use optional fields, but i would recommend to use the same pattern we use across the plotly libs to create these json objects with optional fields. The pattern (in a slightly different/adapted form) is already used for components, see an example here. It is definitely more verbose, but we have many clear advantages. Conversion of your example here would be: type DropdownOption() =
inherit DynamicObj()
static member init
(
label: IConvertible,
value: IConvertible,
?Disabled: bool,
?Title: bool
) =
DropdownOption()
|> DropdownOption.style(
label,value,
?Disabled = Disabled,
?Title = Title
)
static member style
(
label: IConvertible,
value: IConvertible,
?Disabled: bool,
?Title: bool
) =
fun (dro:DropdownOption) ->
label |> DynObj.setValue dro "label" // this is where you decide the property names for json in this pattern
value |> DynObj.setValue dro "value"
Disabled|> DynObj.setValueOpt dro "disabled"
Title |> DynObj.setValueOpt dro "title"
dro |
You might even just go for |
So there is already a good solution using Why do we use records then, is there a plan to replaced them with |
Well I would say I overlooked that while creating the POC. If there are optional fields, the DynamicObj approach is the way to go. |
Okay great. So we can leave this issue open then with the plan of replacing records with I can have a look at it. |
Just for clarification, i would suggest that we only apply that style for objects that have optional fields. Things such as |
Also, i added some tests for serialization of component prop types (which, by design, fail at the moment) 9090c1a. I am not sure which of these records have optional fields, but i would suggest starting there (removing the convert functions, using either JsonProperty or DynObj to make tests green). Would also be awesome if we could set up creation of tests together with component auto generation, but thats another issue. |
Great - Thanks |
☝️ @kMutagene, with the tests you added - how will PR's unrelated to this pass if they're failing already? |
@mr-m-coetzee I added the necessary changes to make the tests work in #33 , just need quick feedback from @plt-joey about the changes to the component generation project |
Current component record implementations does not implement optional fields as optional.
Current state
Taking
DropdownOption
as an example.The fields are described as:
But is implemented as:
Usage:
Proposal
create
method making use of tuples with optional arguments (also allows overloading where curry does not).Usage:
Example
convert
method:The text was updated successfully, but these errors were encountered: