ui icon indicating copy to clipboard operation
ui copied to clipboard

Elt.WithAttrs not found in JavaScript

Open amieres opened this issue 6 years ago • 4 comments

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

amieres avatar Jul 06 '18 08:07 amieres

  1. Oops, my bad -- this method was meant to be an internal helper for server-side rendering. I'll mark it as internal.

  2. 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.

Tarmil avatar Jul 12 '18 11:07 Tarmil

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.

amieres avatar Jul 12 '18 11:07 amieres

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 Elts 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.

Tarmil avatar Jul 12 '18 13:07 Tarmil

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!

amieres avatar Jul 12 '18 14:07 amieres