dotnet-websharper / ui

A reactive UI library for WebSharper.
https://websharper-samples.github.io/ui/
Apache License 2.0
77 stars 22 forks source link

Add new variant for OnAfterRender handler bound in server-side code #250

Open granicz opened 2 years ago

granicz commented 2 years ago

Currently, the templating TP generates the following event handler variants for binding OnAfterRender events:

image

This, however, runs into problems with disambiguation, so code like this doesn't type check properly, like it does with regular events:

Templates.MainTemplate()
    .OAR(fun e ->  // <- FAILS to infer the type of e
        let n = e.Anchors.Parent
        ...
    )

Instead, one has to type annotate the handler argument, which gets pretty annoying:

Templates.MainTemplate()
    .OAR(fun (e: Runtime.Server.TemplateEvent<Templates.MainTemplate.Vars, Templates.MainTemplate.Anchors, JavaScript.Dom.Event>) ->
       ...

I even found that trying to save on the type arguments causes a mismatch:

image

So the current proposal is to generate an addition member for each OAR handler, named as <event-name>_WithModel, with the same signature as the existing variant (TemplateEvent<...> -> unit).