Before I use Feliz style for the auto generated DSL but find it’s a little redundant, so let`s try CE style. The problem with Feliz style is obvious, every time you want to add attribute or some property you need to type the whole name for that component like below:
mudIconButton.onClick (fun _ -> openMenu.Publish not)
For default DOM elements like div, span etc. they belong to a very short named type like html, attr. So you can write it very clearly like:
html.text "hello world"
Anyway I wanted my other generated bingdings can be more clear and I started to experiment on CE style, it should look like this:
onClick (fun _ -> openMenu.Publish not)
I think it looks fatastic and very clear, but after I implemented it I found some drawbacks:
- The intelliense is not very good. In Visual Studio after you typing some char, it brings a lot of options to you and even you press alt+m, you still get some invalid options.
- Fsharp can not always infer the types, sometimes you need to call CAST manually:
html.watch (openMenu, fun isOpen ->
childContentStr "Have fun ✌"
html.watch has multiple overrides, one is aking for return a IFunBlazorNode, even mudDrawer implemented interface IFunBlazorNode, the compiler still give error only if you cast it maunally.
childContent only asks for `IFunBlazorNode list`, F# can infer that so you do not need add cast.
- For CE (computation expression) style, F# do not support override CustomOperation(if the base class has same name for CustomOperation within the child class, fsharp compiler will raise error), so I have to flat inherited properties which may make the binding files a little bigger. And it does not feel good. And the conflicts made me also have to change some property name, like in default attr there is a min method, but if I inherited it then I have to change min to min' or something else to make the conflict go away.
Overall, I kind of like this CE style. But it is very opinionated, so in the Fun.Blazor.Cli I added support for both style for now.
For more information please check Fun.Blazor repo ✌