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

Explicit reuse of values in Lwd_seq.Reducer #39

Open
Julow opened this issue Nov 25, 2022 · 0 comments
Open

Explicit reuse of values in Lwd_seq.Reducer #39

Julow opened this issue Nov 25, 2022 · 0 comments

Comments

@Julow
Copy link

Julow commented Nov 25, 2022

The reducer seems to reuse old values, perhaps using physical equality on the elements of the sequence ?
It could be useful to pass a custom equality function and to define some guarantees about which values are reused.

I don't know which guarantees would be useful but I think it should be possible to avoid the lwd_to_remove marking step in tyxml-lwd's DOM update.
This trick cannot be used in a library where it's not possible to store new state on elements.

Reusing old values in a smart way should be able to avoid false-positives when listing dropped elements.
An element that moves would be removed then added again but this could be optimised an other way.

I noticed that in the code below, if I swap Lwd_seq.bind with Lwd_seq.lift, the whole sequence become dropped on every updates.
This might be because physical equality is lost when it wraps every elements of the sequence into a freshly allocated Lwd_seq.element. In the bind case, the sequence nodes are allocated once and shared (allocated outside of the document).

let$ childs = Lwd_seq.bind childs Fun.id in
let dropped, r = R.update_and_get_dropped !reducer childs in
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

1 participant