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

Provide bridge to carry server-side template assignments to Vars to the client to initialize from #228

Closed granicz closed 2 years ago

granicz commented 3 years ago

Given an HTML template (say, MyTemplate) with bound input controls (say, A and B), instantiated on the server with initial values, currently yields default/empty values for those controls on the client. This is because these assignments happen on the server and they are not connected to the client-side initializer that executes upon page load. Consider the following example:

    MyTemplate()
        .A("some value")
        .B("another value")
        ...
        .Doc()

Here, upon page load, the client controls bound to A and B would be empty, instead of assuming the values given in the server-side code, making initializing view state without further handling more difficult than what it needs to be. This caveat is documented here under the "Mixing client code in server-side templates" subsection:

If you use ws-var="VarName", the corresponding Var will be created on the client on page startup.
However, passing a Var using .VarName(myVar) is not possible, since it would be a server-side Var.

This ticket aims to alleviate this shortcoming by providing the plumbing necessary to ship server-side template assignments to Vars to the client to execute on page load/initialization.