We are happy to announce the release of WebSharper 4.4.0.
You can try it by installing the project templates for .NET Core SDK by running: dotnet new -i WebSharper.Templates::4.4.0.255
or by downloading the templates for Visual Studio 2017 here.
The main highlight of this release is the new Web Workers feature.
Web Workers are a browser feature that allows running JavaScript code in parallel of the main UI thread, taking advantage of concurrency for resource-intensive computations.
Normally, the source code for a Web Worker is a separate JavaScript file that must be passed by URL to the Worker constructor:
/// index.js:
var worker = new Worker("worker.js");
// This code runs in the main thread:
worker.postMessage("Hello, worker!");
/// worker.js:
self.onmessage = e => console.log("Received message from main thread: " + e.data);
WebSharper completely automates the creation of this file, which means you can create a worker directly in code like so:
In F#:
let worker = new Worker(fun self ->
// This code runs in the worker:
self.Onmessage <- fun e -> Console.Log("Received message from main thread: " + string e.Data)
)
// This code runs in the main thread:
worker.PostMessage("Hello, worker!")
In C#:
var worker = new Worker(self =>
{
// This code runs in the worker:
self.Onmessage = e => Console.Log("Received message from main thread: " + (string)e.Data);
});
// This code runs in the main thread:
worker.PostMessage("Hello, worker!");
You can learn more about this feature in the documentation.
Another addition is the proxy for the JavaScript Promise
type. In addition to the type definition, we added a few bells and whistles:
Async
and C# Task
values: Promise.AsAsync
, Promise.OfAsync
, Promise.AsTask
and Promise.OfTask
.promise
computation expression to easily combine promises in F#.Here is the full change log:
Worker
API to WebSharper.JavaScript
.Worker
which takes a function as argument. The compiler automatically compiles this function into a minimal bundle script and compiles the constructor call to reference this script by URL. See the documentation for more details.scriptBaseUrl
which determines the base URL under which the worker scripts are located. The full URL is <scriptBaseUrl>/<assemblyname>/<assemblyname>.<scriptname>.js
, where <scriptname>
is worker
unless specified in the constructor call.WebSharper.JavaScript.JS
from the assembly WebSharper.JavaScript
with the module of the same name from the assembly WebSharper.Main
. This mean that all uses of JSModule
in C# must be replaced with JS
.Promise<'T>
class.Promise
module with functions AsAysnc
, OfAsync
, AsTask
and OfTask
. As*
functions handle rejected promises as follows: if the rejection value is an Error
, then it is used directly as the exception raised from the Async / Task. Otherwise, it is wrapped as the Reason
property of a NonStandardPromiseRejectionException
.promise
computation expression.[Serializable]
requirement for classes used in JSON serialization (RPC, Sitelets, WebSharper.Json
).Router.Create
to parse to option.Content.FromContent(Content<obj>)
to convert an F# content into a C# content.Sitelet.MapContent
.
Sitelet.MapContent : (Async<Content<'T>> -> Async<Content<'T>>) -> Sitelet<'T> -> Sitelet<'T>
Sitelet<obj> Sitelet<obj>.MapContent(Func<Task<Content>, Task<Content>>)
Error
type. This affects exceptions declared with the F# keyword exception
as well as classes inheriting from System.Exception
. This makes it possible to perform runtime type tests (F# :?
, C# is
) against System.Exception
.dotnet build
on a C# project failing to find FSharp.Core.https
.WebSharper.Compiler
, WebSharper.Compiler.CSharp
and WebSharper.Compiler.FSharp
to reference FSharp.Core
4.4.1.0 rather than 4.5.0.0. This fixes assembly loading issues in the Roslyn analyzer. Happy coding!
Can’t find what you were looking for? Drop us a line.