New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow binding template holes to the document #161

Closed
Tarmil opened this Issue Mar 22, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@Tarmil
Member

Tarmil commented Mar 22, 2018

It would be nice to be able to fill holes directly into the document on the client side. For example instead of having to do something like this:

<div id="main" ws-children-template="main">
  <button ws-onclick="Click">Click me</button>
</div>
[<SPAEntryPoint>]
let Main() =
    Template.main()
        .Click(fun e -> ())
        .Doc()
    |> Doc.RunById "main"

we would be able to do this:

<div id="main">
  <button ws-onclick="Click">Click me</button>
</div>
[<SPAEntryPoint>]
let Main() =
    Template()
        .Click(fun e -> ())
        .Bind()

and no elements would be removed and re-rendered, instead the event handler would be added directly to the document.

@Tarmil

This comment has been minimized.

Member

Tarmil commented Mar 23, 2018

I have a working implementation for SPAs. A question now is what to do when the page is served from a sitelet. The server-side templating will have purged all holes from the page, so there is nothing left to bind on the client side. The simplest solution is probably to add an option for server-side templates to not purge holes. There are two possibilities for this:

  1. Put this as an extra static parameter to the type provider.
  2. Put this as an optional argument to .Doc().

I believe solution 2 is better, as it leaves the possibility to instantiate the same template in different sitelet endpoints, some of which use client-side .Bind() and others don't.

@granicz

This comment has been minimized.

Member

granicz commented Mar 23, 2018

Agreed on 2, something like .Doc(removeTemplates=true/false) would work best.

@granicz

This comment has been minimized.

Member

granicz commented Mar 24, 2018

Partially released (client-side .Bind() support) in WebSharper UI 4.2.3.111.

@Tarmil

This comment has been minimized.

Member

Tarmil commented Mar 26, 2018

Closing this ticket, as it is implemented and working well in SPAs. Related work to make Sitelets more amenable to it is in #163.

@Tarmil Tarmil closed this Mar 26, 2018

@Tarmil Tarmil added the 4.2.3.111 label Mar 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment