We are thrilled to announce the availability of WebSharper 3.2, paving the road to further upcoming enhancements to streamline developing and deploying WebSharper apps, and also shipping several key changes summarized here.
Website
This is what pre-3.2 code looked like:
module Site =
...
let Main =
Sitelet.Sum [
Sitelet.Content "/" Home HomePage
Sitelet.Content "/About" About AboutPage
]
[<Sealed>]
type Website() =
interface IWebsite<Action> with
member this.Sitelet = Site.Main
member this.Actions = []
[<assembly: Website(typeof<Website>)>]
do ()
Now you can simply do:
module Site =
...
[<Website>]
let Main =
Sitelet.Sum [
Sitelet.Content "/" Home HomePage
Sitelet.Content "/About" About AboutPage
]
Old code works as before, but we now look for the Website
attribute on values as well if no assembly-level instance is found, yielding the shorter syntax above.
The following code:
Button [Text "some text"]
|>! OnClick (fun e args ->
JS.Alert "Clicked"
)
can now be written as:
Button([Text "some text"])
.OnClick(fun e args ->
JS.Alert "Clicked"
)
This syntax is more familiar to many developers, eliminates the need for a special operator (|>!
), and makes code more discoverable by having API comments and code completion choices available when attaching the event handler.
Traditionally, in sitelet templates you had the following line in the <HEAD>
section to stand for the placeholder for including generated page dependencies (e.g. all the CSS, JS, etc. files that are implicitly referenced in your page):
<meta name="generator" content="websharper" data-replace="scripts" />
With 3.2, you can now refine how these dependencies are inserted if you provide additional placeholders:
styles
: output the generated stylesheets only. Usually, you will want to put this placeholder in the <HEAD>
section.meta
: output the client-server integration (arguments to server-side controls, etc.) bits only. You will want this in <HEAD>
When either of these are present, scripts
only outputs the JavaScript dependencies, making it possible to place this placeholder anywhere else, away from the other bits, say, to the tail of the <BODY>
element.
A typical new template might thus be:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta data-replace="meta" />
<meta data-replace="styles" />
...
</head>
<body>
...
<script data-replace="scripts"></script>
</body>
</html>
The full list of items completed since the last 3.1.6
release:
FuncWithOnlyThis
type, compile error on invalid use of FuncWithThis
JQuery.Add(JQuery)
binding missingSeq.last
ClientSide
doesn't incur a dependency on the declaring type of the invoked method[<Name>]
for its fieldsIOException
on changed file[<Website>]
on a Sitelet<'T>
valueHtml.Client
: Add chainable extension methods for event handlersSeq.distinct
/distinctBy
proxy only compares hashesWebSharper.Compiler
nuget packagesprintf
Is Not Properly CompiledWebSharperProject
=Ignore
build task optionSitelet.Infer
: add EndPointAttribute
as synonym for CompiledNameAttribute
Sitelet.Infer
: allow prefixing union case's CompiledName
with /
Just a note: CloudSharper out-of-the-box templates still use 3.1 - we will be migrating these to 3.2 in the following days, keep an eye on our blog for when this is finalized.
Happy coding!
Can’t find what you were looking for? Drop us a line.
20221229 · 30 min read
20211230 · 20 min read