Fabulous: Add WebAssembly support

Created on 11 Sep 2019  路  5Comments  路  Source: fsprojects/Fabulous

This is related to closed issue #112
The advantage to Xamarin.Forms is that that it works client side. Fabulous works for so many platforms now (including WPF), if it worked in the browser, it would be almost the holy grail. I am not as interested in the server side web idea of ooui as I found the WebAssembly aspect awesome. A WA version of the XF app could use serverless (Azure Functions) as the backend the same as the other heads. ooui has not been active, but how feasible would it be to use the WebAssembly aspects to enable Fabulous to create a XF WA head?

webassembly enhancement

All 5 comments

Fabulous works for so many platforms now (including WPF), if it worked in the browser, it would be almost the holy grail.

Sorry, I might state the obvious but I just want to be extra clear in my response. 馃檪

We need to clearly separate Xamarin.Forms from Fabulous from Fabulous.XamarinForms.

  • Xamarin.Forms

    • A framework for writing cross-platform apps. Officially support Android, iOS, UWP, WPF, MacOS, Tizen, more platforms can be unofficially supported by the community (like Ooui which adds WASM to XF)

  • Fabulous

    • Platform-agnostic MVU library with a bunch of helpers - really just a .NET Standard library for framework authors

  • Fabulous.XamarinForms

    • A concrete framework using MVU and built on top of Xamarin.Forms, that allows to write cross-platform apps and deploy on all platforms supported by XF

So "Fabulous works for so many platforms" is both correct and not correct.

Fabulous is platform-agnostic, it can be executed on all platforms - whichever one that accepts .NET Standard 2.0 - but in itself it can't run anywhere because it has no UI implementation.

Fabulous.XamarinForms relies completely on Xamarin.Forms, and can be used everywhere Xamarin.Forms has an implementation available.

WASM + Fabulous.XamarinForms

Using the explanation just above, Fabulous.XamarinForms won't provide a WASM head by itself.
This WASM implementation of Xamarin.Forms first needs to come from the XF team (or from the XF community).

Ooui.Forms tried to tackle the subject, but it's an immense work load to fully implement XF for a new platform and it seems it doesn't interest a lot of people unfortunately, hence the general inactivity of Ooui.

So to be able to use Fabulous.XamarinForms to write a WASM app powered by XF, one either needs to contribute to Ooui.Forms/Ooui.WASM or starts its own WASM implementation of XF.

Other ways to achieve WASM with Fabulous

If we set Fabulous.XamarinForms aside for a moment, we can think about other ways to write WASM apps with F#/MVU

  • Bolero can be a viable option. It's not Fabulous but uses the exact same logic (uses Elmish, which Fabulous currently uses a fork of).
  • Write a new Fabulous.Uno framework making use of the Uno platform instead of Xamarin.Forms. It's similar to XF and already officially support a bunch of platforms including WASM
  • Write a new Fabulous.* framework using another .NET UI framework targeting WASM

For Bolero, we can imagine in the future to be able to use the same code base for both Fabulous apps and Bolero since they use the same MVU pattern (see #486 for explanation).
You will need to write 2 UIs (one Bolero, one Fabulous.XF) but the update logic/state will be 100% shareable.

The advantage of Uno would be to have only one codebase for all the platforms including WASM.

Summing up

Writing apps using Fabulous running on WASM is currently quite a lot of work.

Fabulous.XamarinForms needs initiative like Ooui to bring WASM support to XF, but it doesn't seem to take off, and the Xamarin.Forms team doesn't seem to be interested in taking it further...

The most promising option would be to create Fabulous.Uno.
Uno is gathering a lot of people recently, so providing support for this framework with Fabulous would be highly beneficial for both Fabulous and Fabulous users.
The PR #530 will also greatly simplify creating new such framework by automating the most tedious parts.

Looks like there might be another way for Fabulous.XamarinForms to go WASM
https://platform.uno/announcing-uno-platform-2-0/

Couldn't get it to work for now.

Apparently there is some limitations between F# and WebAssembly.
FSharpEvent, printf and alike are crashing for various reasons (NullRef, List empty)

For those interested on using Fabulous to write WebAssembly apps, you can take a look at Uno.Fabulous from @jeromelaban.

It's an experimental framework built on both Fabulous and Uno Platform, currently only runnable for WASM.

Thanks @TimLariviere, yes this is a proof of support, really. There are a few things that need to be added to Uno directly, but overall, supporting Fabulous is within reach :)

iOS, Android can be supported easily though, though the codegen must be run for each of those as well.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sergey-tihon picture sergey-tihon  路  9Comments

willsam100 picture willsam100  路  3Comments

dsyme picture dsyme  路  5Comments

Happypig375 picture Happypig375  路  4Comments

slang25 picture slang25  路  6Comments