Skip to content
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

Dynamic documents and lost updates #36

Open
dariusf opened this issue Jun 11, 2022 · 2 comments
Open

Dynamic documents and lost updates #36

dariusf opened this issue Jun 11, 2022 · 2 comments

Comments

@dariusf
Copy link

dariusf commented Jun 11, 2022

Hi, I was trying out the Brr backend and had a couple of questions.

let ui =
  let count = Lwd.var 0 in
  let on_click () = Lwd.set count (Lwd.peek count + 1) in
  let button =
    Lwd.map
      ~f:(fun i ->
        let btn = El.button [El.txt' (string_of_int i)] in
        Ev.listen Ev.click (fun _e -> on_click ()) (El.as_target btn);
        btn)
      (Lwd.get count)
  in
  Elwd.div [`R button]

The rest of the file is the same as in the Brr example. If I replace the last line with button, the button no longer updates.

  1. I'm guessing this is due to the mismatch between the pure interface and the statefulness of the DOM. Should we always ensure that the top-level node is not dynamic, or is there a better workaround? Maybe this could be documented somewhere.
  2. Is this what the commented line is meant to address?

Anyway, I really like Lwd so far, awesome work!

@let-def
Copy link
Owner

let-def commented Sep 5, 2022

Hi Darius, sorry for the late answer.

Indeed, there is a mismatch, usually just at the node at the junction between Lwd and DOM.
The commented line is meant to address that though this solution has shortcomings too.
First it would be nice to check that the ui node is not already the only child of body. Otherwise the side effect might reset some internal browser state (such as focused element and selected text).
And then, it works if there is only a single child, since it removes all other nodes. That could be worked around, but I have no time to spend on that in the near future :/.

@let-def
Copy link
Owner

let-def commented Sep 5, 2022

And thanks, I am glad that you like Lwd!

I am really busy for now but I would like to give it some love in the next two years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants