Skip to content
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

Fix example in readme which doesn't handle no children #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mattvague
Copy link

It seems that the FixedSizeTree example in the readme doesn't work because it expects all nodes to have children which they don't. Wasn't sure though if if the right solution was to give all leaf nodes an empty children array, or to just handle no children array. Thoughts?

Copy link
Owner

@Lodin Lodin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that issue!

@@ -72,7 +72,7 @@ const treeNodes = [
const getNodeData = (node, nestingLevel) => ({
data: {
id: node.id.toString(), // mandatory
isLeaf: node.children.length === 0,
isLeaf: !!node.children,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess, it should be reversed: a leaf element is an element without children. For the documentation purposes, I suggest using a more explicit check:

Suggested change
isLeaf: !!node.children,
isLeaf: node.children == null || node.children.length === 0,

@@ -95,6 +95,8 @@ function* treeWalker() {
// the `getNodeData` function constructed, so you can read any data from it.
const parent = yield;

if (!parent.node.children) continue
Copy link
Owner

@Lodin Lodin Jul 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why you are using continue outside of for loop?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants