Home

Awesome

Fun.Blazor Nuget

image

This is a project to make F# developer to write blazor easier.

  1. Use F# ❤️😊 for blazor
  2. Computation expression (CE) style DSL for internal and third party blazor libraries
  3. Dependency injection (html.inject)
  4. Adaptive model (adaptiview/AdaptivieForm) (recommend), elmish model (html.elmish)
  5. Giraffe style routing (html.route/blazor official style)
  6. Type safe style (Fun.Css)
  7. Convert html to CE style by Fun.Dev.Tools

Check the WASM Docs for more 🚀

Donation

If you find my projects helpful and would like to support my work, consider making a donation via PayPal. Your support is greatly appreciated!

<a href="https://paypal.me/wubinwen" style="display: flex; align-items: center; gap: 12px;"> <img src="https://www.paypalobjects.com/paypal-ui/logos/svg/paypal-color.svg" height="30"> </a>

Start to use

dotnet new install Fun.Blazor.Templates::4.0.2
dotnet new fun-blazor -o FunBlazorDemo1

Requires dotnet 8

Code samples

// Functional style
let demo (str) = fragment {
    h2 { $"demo {str}" }
    p { "hi here" }
}

// Class style
type Foo() =
    inherit FunComponent()

    let mutable count = 0

    override _.Render() = main {
        h1 { "foo" }
        demo $"hi {count}"
        button {
            onclick (fun _ -> count <- count + 1)
            "Click me"
        }
    }

CE build performance

There are some tests in here, in summary, below are some recommend ways for better build time performance (but it can reduce runtime performance because we cannot inline and need to allocate memory on head for creating array or list)

Local development

You can run dotnet fsi build.fsx -- -h to check what is available to help you get started.

Benchmark

BenchmarkDotNet v0.13.12, Windows 11 (10.0.22631.3007/23H2/2023Update/SunValley3) 12th Gen Intel Core i7-12700H, 1 CPU, 20 logical and 14 physical cores .NET SDK 8.0.100 [Host] : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2 DEBUG DefaultJob : .NET 8.0.1 (8.0.123.58001), X64 RyuJIT AVX2

MethodMeanErrorStdDevRatioRatioSDGen0AllocatedAlloc Ratio
RenderWithRazorCSharp234.1 ns3.59 ns3.36 ns1.000.000.0298376 B1.00
RenderWithFunBlazorInlineCE363.5 ns4.14 ns3.67 ns1.550.030.0443560 B1.49
RenderWithFunBlazorArray499.0 ns9.82 ns10.91 ns2.140.050.11541448 B3.85
RenderWithBolero507.9 ns9.74 ns11.21 ns2.170.070.11731480 B3.94