dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
593 stars 52 forks source link

Add JS.Verbatim and JS.Html helpers #1333

Closed Jand42 closed 10 months ago

Jand42 commented 1 year ago

To allow printing any code fragments directly (unchecked) to .js output, also html fragments for .jsx. You can only use constant strings or interpolated strings as argument.

   JS.Verbatim $"console.log({x})" // translated to: `(console.log(x))`
   JS.Html $"<div>{x}</div>" // translated to: `(<div>{x}</div>)`
granicz commented 1 year ago

Also, when translating placeholders like:

<{QRCode} message={value} size="0.5"></{QRCode}>

... omit the {}'s from around QRCode, because we can detect that <{...}> and </{...}> placeholders yield custom element names.

granicz commented 1 year ago

I really find the name JS.Html confusing - since it's a trigger to generate .jsx, I'd rename it to something more explicit such as JS.jsx. One bonus is that when renamed properly, it also becomes compatible with vscode-template-fsharp-hightlight.

Jooseppi12 commented 10 months ago

Added a JS.Jsx function that is equivalent of the JS.Html function and exposed lowercase variants of those two.