WebSharper 4 was a long journey. Started from the initial idea to add C# support and move to read F# source code directly for covering F# language features better, a lot of other new features requested by the community or needed for ongoing projects were added to make development with WebSharper even more powerful.
Today we are publishing the full stack of WebSharper
libraries, compilers and extensions with the 4.0-rc
version.
Feature-wise these are the same as the latest Zafir
(WebSharper 4 codename) releases.
WebSharper 4 is open source under the Apache 2.0 License. Contributions are welcome at the GitHub repository.
For updating previous WebSharper 3 projects and breaking changes, look for the upgrade guide.
We are continuing to round out the documentation with more help for beginners. Your questions are welcome on the forums. All the source for the documentation browser are also available on GitHub, please feel free to submit issues and pull requests.
Try WebSharper has also been updated, test out WebSharper for both languages right in your browser.
You can download the VSIX installer for Visual Studio 2015/17 or download a template straight from the documentation subsite, look for "Create a project" in the top-right drop-down menu.
Big thanks to everyone who has been testing WebSharper 4 beta and submitted bug reports, questions and feature ideas!
[Remote] // Runs on the server
public static Task<string> GetMessage() => Task.FromResult("Hello world!");
[JavaScript] // Runs on the client, seamless type-safe asynchronous call
public static async Task SayHello() => WebSharper.JavaScript.Console.Log(await GetMessage());
ul( // Create HTML list from a query. Syntax is reusable for both server and client
(from p in people
where p.Age > 18
select li(attr.@class("person-name"), p.Name)).ToArray()
);
byref
and &
operator, inner generic functions, pattern matching on arrays, statically resolved type parameters, struct unions and records.
While WebSharper 3 focused on the functional programming aspects of F#, with the introduction of C# support, WebSharper 4 embraces object-oriented programming too for both languages. // Passing byref to C# and consuming a byref return
// Now all working in JavaScript translation, so you can mix C# and F# anywhere
let mutable myArr = [| 0; 1 |]
let res : byref<int> = MyCSharpLibrary.ByRefReturn(&myArr.[0])
UI.Next has been updated with a newer templating syntax and engine that allows declaratively reusing sub-templates and has more flexibility for filling in holes while keeping strong typing. For details, see the documentation.
Here is a sample todo application with beautifully small code required in C# and in F#.
WebSharper.JavaScript
namespace, named Union
and Optional
. These are similar to Choice
and Option
types of F#, but work as TypeScript's erased unions in the JS translation. Conversion functions are available under modules Optional
and Union
.<WebSharperDownloadResources>True</WebSharperDownloadResources>
in your project file to have WebSharper download all remote js/css defined in current project and all references. Add
<add key="UseDownloadedResources" value="True" />
to your <appSettings>
section in web.config.List.map2
. This is done by analyzing uses of the function parameter, not making any assumptions.For the 4.0 stable release, we will publish a site to browse what .NET types and methods WebSharper translation cover via proxies. We will use this ourselves to expand coverage where lacking. We will also address bug reports coming in for the RC release.
High on our priority list for 4.x versions:
.d.ts
declarations, output .d.ts
for WebSharper code.wasm
files and compile a subset of the languages to WebAssemblyDiscuss upcoming features and make feature requests on the WebSharper forums.
Happy coding!
Can’t find what you were looking for? Drop us a line.