-
Notifications
You must be signed in to change notification settings - Fork 25
Brr: Better ux for inserting reactive elements in the DOM #64
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
Open
panglesd
wants to merge
8
commits into
let-def:master
Choose a base branch
from
panglesd:better-ux-for-inserting-el-in-dom
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
19f7019
Add "sibling insert" API for brr lwd
panglesd fd969e4
Update brr examples to use new API
panglesd 703c49f
Lwd brr: Add `set_children` API
panglesd 911e7e9
Lwd brr: Update the docs for entry-points in the DOM
panglesd 7cf9eb2
Fix set_children initial value
panglesd a53c4ae
Brr: Fix release behavior and doc
panglesd 576abc0
Brr: Add `append_child` and `prepend_child`
panglesd 2c0f56c
Avoid `ignore` in examples
panglesd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -409,3 +409,61 @@ let ul = cons Name.ul | |||||||||||||
| let var = cons Name.var | ||||||||||||||
| let video = cons Name.video | ||||||||||||||
| let wbr = void_cons Name.wbr | ||||||||||||||
|
|
||||||||||||||
| type root = t Lwd.root | ||||||||||||||
|
|
||||||||||||||
| let insert first_insert anchor reactive = | ||||||||||||||
| let root = Lwd.observe reactive in | ||||||||||||||
| let last_element = ref (Lwd.quick_sample root) in | ||||||||||||||
| first_insert anchor [!last_element]; | ||||||||||||||
| let on_invalidate _ = | ||||||||||||||
| let _ : int = | ||||||||||||||
| G.request_animation_frame @@ fun _ -> | ||||||||||||||
| let new_element = Lwd.quick_sample root in | ||||||||||||||
| if !last_element = new_element then () | ||||||||||||||
| else ( | ||||||||||||||
| El.insert_siblings `Replace !last_element [ new_element ]; | ||||||||||||||
| last_element := new_element | ||||||||||||||
| ) | ||||||||||||||
| in | ||||||||||||||
| () | ||||||||||||||
| in | ||||||||||||||
| Lwd.set_on_invalidate root on_invalidate; | ||||||||||||||
| root | ||||||||||||||
|
|
||||||||||||||
| let insert_sibling where anchor reactive = | ||||||||||||||
| let first_insert = El.insert_siblings where in | ||||||||||||||
| insert first_insert anchor reactive | ||||||||||||||
|
|
||||||||||||||
| let append_child anchor reactive = | ||||||||||||||
| insert El.append_children anchor reactive | ||||||||||||||
|
|
||||||||||||||
| let prepend_child anchor reactive = | ||||||||||||||
| insert El.prepend_children anchor reactive | ||||||||||||||
|
|
||||||||||||||
| let set_children el children = | ||||||||||||||
| let reactive = | ||||||||||||||
| let children, impure_children = consume_children children in | ||||||||||||||
| match impure_children with | ||||||||||||||
| | None -> El.set_children el children; Lwd.pure el | ||||||||||||||
| | Some children -> | ||||||||||||||
| let root = Lwd.observe children in | ||||||||||||||
| let c = Lwd.quick_sample root in | ||||||||||||||
| El.set_children el (Lwd_seq.to_list c); | ||||||||||||||
| Lwd.quick_release root; | ||||||||||||||
| update_children el children | ||||||||||||||
|
Comment on lines
+450
to
+454
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well there is a bug here. Update_children expects no children at the beginning, so it will add them (again) and we end up with a duplicated initial value.
Suggested change
|
||||||||||||||
| in | ||||||||||||||
| let root = Lwd.observe reactive in | ||||||||||||||
| let _el = Lwd.quick_sample root in | ||||||||||||||
| let on_invalidate _ = | ||||||||||||||
| let _ : int = | ||||||||||||||
| G.request_animation_frame @@ fun _ -> | ||||||||||||||
| let _el = Lwd.quick_sample root in | ||||||||||||||
| () | ||||||||||||||
| in | ||||||||||||||
| () | ||||||||||||||
| in | ||||||||||||||
| Lwd.set_on_invalidate root on_invalidate; | ||||||||||||||
| root | ||||||||||||||
|
|
||||||||||||||
| let release root = Lwd.quick_release root | ||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.