ui
ui copied to clipboard
Elt.WithAttrs not found in JavaScript
Just a couple of issues:
1.- Elt.WithAttrs
gives message: Method name not found in JavaScript compilation: (WithAttrs : ...
2.- Elt.AddClass
adds an extra space that Elt.RemoveClass
does not remove
http://try.websharper.com/snippet/user3359/0000Lb
-
Oops, my bad -- this method was meant to be an internal helper for server-side rendering. I'll mark it as internal.
-
Indeed, I'm fixing this. While looking at it I also found out that calling
Elt.AddClass
repeatedly with the same class adds it multiple times, so I'll fix that too.
WithAttrs
seems to me like a very useful function to add attributes to an element defined with another function. It makes it composable. In fact, I think something similar existed in prior versions of WebSharper using operators, but I may be wrong.
My first impression on this is that given how attributes are implemented on the client side, I think adding one to an existing element would be pretty non-trivial. I'm not certain it can be done without adding an extra Var
inside Elt
, which would be a performance hit for all Elt
s so I'd rather avoid that.
That being said, I hope I'm wrong and this can actually be done at no extra cost; I'll look into it.
Thanks for looking into it. I appreciate it.
What I really meant to say is: not adding an attribute to an existing Elt but creating another Elt instance with the added attributes.
let oldElement = div [ attr.style "background: white"] [ yield text "Hello" ; yield! children ]
// oldElement created somewhere else but used as base for newElement ....
let newElement = oldElement.WithAttrs [ attr.title "Some Title" ; attr.style "font-size: 20px" ]
Hopefully, that would not impact performance, we would not want that.
BTW, great job!