Skip to content

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

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,

isOpenByDefault: true, // mandatory
name: node.name,
nestingLevel,
Expand All @@ -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?


for (let i = 0; i < parent.node.children.length; i++) {
// Step [3]: Yielding all the children of the provided component. Then we
// will return for the step [2] with the first children.
Expand Down