-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Updated the public API to no-longer extract nodes #108
Conversation
"height": 20, | ||
"top": 50, | ||
"left": 50, | ||
"right": 50, |
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.
why does it compute right and bottom?
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.
Those layout properties are set here:
https://github.com/facebook/css-layout/blob/master/src/Layout.js#L416
The design I use for react-native is that there are two trees: the shadow node tree which is completely react-native specific and the layout tree which is the one in css-layout. Because you cannot extend C-struct easily what i'm doing instead is that each layout node has a void* pointer to the corresponding shadow node and a method getChildren(void*) that returns the new set of layout nodes for children.
this is indeed a bit convoluted but has the great advantage of letting you manage your tree without impacting the css tree structure |
That's very similar to our approach with d3fc, we have the SVG 'DOM' node tree which we cannot add a
The With the current public API the
I cannot link the nodes in (3) back to (1). I hope that makes sense! |
This looks like a step in the right direction and addresses a lot of the existing issues. It's interesting to see how projects like ReactCanvas have also worked around difficulties with the library - https://github.com/Flipboard/react-canvas/blob/master/lib/layoutNode.js Hopefully that can be avoided more often after these changes. |
Feel free to merge it in and iterate on the api :) |
Thanks for the info @fsbdev - I can see that ReactCanvas are also not using the public API for the same reasons as d3fc. Hopefully this change will make that possible. |
Updated the public API to no-longer extract nodes
Can you publish 0.0.3 to npm? |
I've been trying to automate the npm publish via TravisCI, see #113 - but have manually published 0.0.3 to npm just to get things moving. |
When this project was first released the example in the README didn't execute as expected (#24) so an adapter was put in place to recreate this behaviour (#50).
However, on reflection my feeling is that this was a mistake! I think code provided in the README was more illustrative than literal, especially as the early users of this library were clearly not using the JavaScript API.
The current adapted JS API still has issues #61 #62 - I also think that it has some fundamental design flaws.
Currently
computeLayout
takes a node tree, and optionally 'fills' it out with the required layout / children and style properties. It performs layout, then extracts the layout information into its own tree, which is then returned.There are a few issues with this approach:
computeLayout
which can be considered a side-effect.With d3fc we do not use the adapted API due to (2) above.
I propose that the public API should be changed so that it mutates the node tree that is passed to
computeLayout
, adding the layout information to each node. This should be made clear by having a void function.I have tested this updates implementation against d3fc and it works for our needs.
fixes #61 fixes #62 fixes #107