-
Notifications
You must be signed in to change notification settings - Fork 197
Lib: fix #333 #345
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
Merged
Merged
Lib: fix #333 #345
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,13 +42,10 @@ module Xml = struct | |
| type keyboard_event_handler = Dom_html.keyboardEvent Js.t -> bool | ||
| type attrib_k = | ||
| | Event of biggest_event_handler | ||
| | Attr of Dom.attr Js.t | ||
| | Attr of Js.js_string Js.t option React.S.t | ||
| type attrib = aname * attrib_k | ||
|
|
||
| let attr name v = | ||
| let a = Dom_html.document##createAttribute(Js.string name) in | ||
| a##value <- v; | ||
| name,Attr a | ||
| let attr name v = name,Attr (React.S.const (Some v)) | ||
|
|
||
| let float_attrib name value : attrib = attr name (js_string_of_float value) | ||
| let int_attrib name value = attr name (js_string_of_int value) | ||
|
|
@@ -78,9 +75,15 @@ module Xml = struct | |
|
|
||
| let attach_attribs e l = | ||
| List.iter (fun (n,att) -> | ||
| let n = Js.string n in | ||
| match att with | ||
| | Attr a -> ignore(e##setAttributeNode(a)) | ||
| | Event h -> Js.Unsafe.set e (Js.string n) (fun ev -> Js.bool (h ev)) | ||
| | Attr a -> | ||
| (* Note that once we have weak pointers working, we'll need to React.S.retain *) | ||
| let _ : unit React.S.t = React.S.map (function | ||
|
Member
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. Assuming that GC of signals on javascript might be one day fixed, shouldn't this use
Member
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. I'll just add a comment about it. |
||
| | Some v -> ignore(e##setAttribute(n, v)) | ||
| | None -> ignore(e##removeAttribute(n))) a | ||
| in () | ||
| | Event h -> Js.Unsafe.set e n (fun ev -> Js.bool (h ev)) | ||
| ) l | ||
|
|
||
| let leaf ?(a=[]) name = | ||
|
|
@@ -190,6 +193,7 @@ module Util = struct | |
|
|
||
| let update_children (dom : Dom.node Js.t) (nodes : Dom.node Js.t t) = | ||
| removeChildren dom; | ||
| (* Note that once we have weak pointers working, we'll need to React.S.retain *) | ||
| let _s : unit React.S.t = fold (fun () msg -> merge_msg dom msg) nodes () | ||
| in () | ||
| end | ||
|
|
@@ -209,10 +213,7 @@ module R = struct | |
| type attrib = Xml.attrib | ||
|
|
||
| let attr name f s = | ||
| let a = Dom_html.document##createAttribute(Js.string name) in | ||
| let _ = Xml_wrap.fmap (fun s -> match f s with | ||
| | None -> () | ||
| | Some v -> a##value <- v) s in | ||
| let a = Xml_wrap.fmap f s in | ||
| name,Xml.Attr a | ||
|
|
||
| let float_attrib name s = attr name (fun f -> Some (js_string_of_float f)) s | ||
|
|
@@ -263,6 +264,15 @@ module R = struct | |
|
|
||
| module Svg = Svg_f.MakeWrapped(Xml_wrap)(Xml_wed_svg) | ||
| module Html5 = Html5_f.MakeWrapped(Xml_wrap)(Xml_wed)(Svg) | ||
| let filter_attrib (name,a) on = | ||
| match a with | ||
| | Xml.Event _ -> | ||
| raise (Invalid_argument "filter_attrib not implemented for event handler") | ||
| | Xml.Attr a -> | ||
| name, | ||
| Xml.Attr | ||
| (React.S.l2 | ||
| (fun on a -> if on then a else None) on a) | ||
| end | ||
|
|
||
| module To_dom = Tyxml_cast.MakeTo(struct | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense (from an efficiency perspective) to keep a constant attribute constructor, with the new signal attribute ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
React already has fast path for constant signals. I don't think you'll gain any efficiency adding an extra constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.