-
Notifications
You must be signed in to change notification settings - Fork 0
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
walkUp
function
#20
base: main
Are you sure you want to change the base?
walkUp
function
#20
Conversation
✅ Deploy Preview for treecle ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
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.
See comments. Also, please run ESLint and fix issues.
Added in a call to |
if (ret !== undefined) { | ||
return ret; | ||
} | ||
assertParentPointers.call(this, node, "Cannot walk up the tree from a node with no parent pointer."); |
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.
Can we print something more useful? Since we check on every node, it would help debugging to know which node actually failed.
*/ | ||
export default function walkUp (node, callback) { | ||
while (node) { | ||
const ret = callback(node); |
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.
Currently even in a tree with zero parent pointers you get the callback executed once. Is that what's best for the use cases that use this? Not a rhetorical question, I don't know. We need to look at the code using this function to see what would work well for these use cases.
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.
The main issue I see is the fact that we could execute an arbitrary number of callbacks before running into an error in the case where some ancestor node n
nodes away doesn't have parent pointers set. The best option might even be to walk up the entire tree before executing any callbacks, and asserting parent pointers, and then after completing the first walk up, doing a second pass where you execute the callback. But of course, this also has a performance increase factor of 2, but might be worth it! Of course, if the callback didn't do any sort of mutation, then it would be safe to call before discovering an error, but I don't think we can count on that. I'd probably lean toward the above idea (walking up twice). What do you think @LeaVerou?
import copy from "./utils/copy.js"; | ||
|
||
const tree = copy(trees[0]); | ||
updateParents(tree); |
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.
Might want to have some throws
tests too, for when we don't have parents. Or should that just be handled in the parents tests?
A part of use cases discussed in #11