-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Update RST spec to include a parent and/or sibling pointer(s) #1085
Comments
If we agree that this is an acceptable change to the RST spec I can include the changes to the adapters and spec alongside the work I'm doing integrating a CSS parser with the RST traversal stuff. |
Would adding a |
In what situations could an RST represent a set of child nodes that aren't finite, unique and ordered? I think even if an element was repeated it would be represented by a unique node, but I'm not sure. Having just a |
All three seem reasonable fwiw (nextSibling, prevSibling, parent) but it'd be nice to minimize the API surface :-) |
While working on #1086 I found that the only time I needed to get the parent was to get a sibling, and I never had to match a previous sibling since CSS selectors only match following siblings. So I think we could get away with just |
If we have next, I think we need prev. I'm less concerned about parent tho, since theoretically you got to a node from the parent. |
Without a |
@nfcampos that's exactly how it does it: https://github.com/airbnb/enzyme/blob/master/packages/enzyme/src/RSTTraversal.js#L74-L76 I was only thinking about it in the context of the selector API, but a |
Sounds like there's use cases for all three then. @lelandrichardson, thoughts? |
@aweary i worry about adding these types of things when JS doesn't have weak references. I think it also makes actually building an RST much more complicated. Since this is just traversal stuff, It'd be nice if any logic around prev/next sibling etc was contained inside enzyme. If we wanted to transform an RST into a structure that had these pointers, that might make sense... but i also am not sure i'm convinced that this is a good idea. |
*and possibly a
parent
pointer.Currently, the RST spec only allows one form of traversal: from root to leaf. This isn't ideal, since we occasionally need to check some predicate for either a sibling node. I suggest we add a
nextSibling
pointer, so we can traverse siblings as a singly linked list (prevSibling
could be included but I haven't found it super useful yet)I did some work with a similar tree format and found that it wasn't too hard to add these pointers.
As an example of an existing pain point, think about adjacent sibling selectors. Currently, we need to find the parent of the node (if we don't already have a reference to it that means we need a reference to the root node and have to traverse the ~whole tree in the worst case) and iterate through the children.
With a
nextSibling
pointer we could just do a constant-time operation by running the predicate againstnode.nextSibling
. It also makes general sibling selectors easier.I'm not sure if a
parent
pointer would be useful yet, but it could be 🤔The text was updated successfully, but these errors were encountered: