You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With the hindsight from using UI in many applications, I've come to the conclusion that:
The vast majority of use cases for DOM elements do not make any use of Elt-specific APIs like .Dom, .OnEvent, .AppendDoc, etc and could just as well have type Doc.
There are many situations where we need to upcast from Elt to Doc, which is more verbose than necessary.
Examples:
Branches with different types:
if someCondition then
Doc.Empty
else
span [][text "test"]:> Doc
Higher-order functions:
letmkList(count:int)(generate:int ->Doc)=
ul [][for i in1..count doyield li [][generate i]]letelt= mkList 10(fun i -> span [][text (string i)]:> Doc)
Lists that the compiler would otherwise mistakenly think are heterogeneous:
@Tarmil I'm all for it. I can't think of one single case where we use Elt-specific APIs in our code. on the other hand, upcasts from Elt to Doc are pervasive.
With the hindsight from using UI in many applications, I've come to the conclusion that:
The vast majority of use cases for DOM elements do not make any use of
Elt
-specific APIs like.Dom
,.OnEvent
,.AppendDoc
, etc and could just as well have typeDoc
.There are many situations where we need to upcast from
Elt
toDoc
, which is more verbose than necessary.Examples:
Branches with different types:
Higher-order functions:
Lists that the compiler would otherwise mistakenly think are heterogeneous:
yield
(this one will apparently be fixed in F# 4.5):I therefore propose that:
div
,span
, etc from theWebSharper.UI.Html
module should return typeDoc
instead ofElt
.WebSharper.UI.Html.Elt
should be added, with these same functions returningElt
.Obviously this is a breaking change, but I think it's a worthwile one that will both make learning easier and real-life code more readable.
Note that this only concerns the F# API; C# performs enough automatic upcasting that this is not problematic there.
The text was updated successfully, but these errors were encountered: