Skip to content
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

Elt.WithAttrs not found in JavaScript #181

Open
amieres opened this Issue Jul 6, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@amieres
Copy link

amieres commented Jul 6, 2018

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

@Tarmil

This comment has been minimized.

Copy link
Member

Tarmil commented Jul 12, 2018

  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.

@amieres

This comment has been minimized.

Copy link
Author

amieres commented Jul 12, 2018

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.

@Tarmil

This comment has been minimized.

Copy link
Member

Tarmil commented Jul 12, 2018

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.

@amieres

This comment has been minimized.

Copy link
Author

amieres commented Jul 12, 2018

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
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.