Skip to content
This repository was archived by the owner on Oct 11, 2023. It is now read-only.

Conversation

irokas
Copy link
Contributor

@irokas irokas commented Jul 25, 2018

No description provided.

Copy link
Member

@parisk parisk left a comment

Choose a reason for hiding this comment

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

A few code styling comments to begin with 😄. Afterwards, we will write a couple of tests and we are good to go!

src/main.js Outdated
@@ -2,7 +2,19 @@ function convertItemsToUnorderedList(listItems) {
const ulElement = document.createElement("ul");
listItems.forEach(item => {
const liElement = document.createElement("li");
liElement.textContent = item.name;
liElement.classList.add("fs-api-entry");
if (item.type === "file") {
Copy link
Member

Choose a reason for hiding this comment

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

Assuming we are are getting valid input every time, we can ditch the if statement here in favor of a template literal (learn more):

liElement.classList.add(`fs-api-${item.type}`);

src/main.js Outdated
} else {
liElement.classList.add("fs-api-directory");
}
const spanElement = document.createElement("span");
Copy link
Member

Choose a reason for hiding this comment

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

Can you please rename spanElement to something more semantic (e.g. nameElement)?

We favor variable names describing the content of each variable, instead of their technical aspects.

src/main.spec.js Outdated
expect(ul.children[3].children[0].textContent).toBe("SFile.sth");
expect(ul.children[4].children[0].textContent).toBe("test.go");
expect(ul.children[5].children[0].textContent).toBe("Troll.go");
for (i = 0; i < ul.length; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

First, we should not use ul.length, as it is not in the spec of the HTMLUListElement (read the spec).

Next, we should simplify this. An example that could work:

for (const li of ul.children) {
  // ...do thing here
}

src/main.spec.js Outdated
expect(ul.children[4].classList.contains("fs-api-file")).toBe(true);
expect(ul.children[5].classList.contains("fs-api-file")).toBe(true);

for (i = 0; i < 6; i++) {
Copy link
Member

Choose a reason for hiding this comment

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

We should simplify this as well. Example:

for (const li of ul.children) {
  // ...do thing here
}

Copy link
Member

@parisk parisk left a comment

Choose a reason for hiding this comment

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

A few more naming updates and I think we are good to go!

src/main.spec.js Outdated
trees[0].children[1].children[1].children[1].children[0].textContent
).toBe("yarn.lock");

//expect(trees[0].children[1].children[0].children[1].textContent).toBe("yarn.lock");
Copy link
Member

Choose a reason for hiding this comment

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

Remove this line please 😄.

src/main.spec.js Outdated
expect(trees[0].children[5].children[0].textContent).toBe("Troll.go");

expect(
trees[0].children[1].children[1].children[0].children[0].textContent
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm... I think this is a bit illegible here. What about replacing trees[0].children[1].children[1] with something more semantic and reusing it also in the test below?

e.g.

const vendorChildren = trees[0].children[1].children[1];  // or vendorSubTree, or something else that sounds more relevant

Copy link
Member

@parisk parisk left a comment

Choose a reason for hiding this comment

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

I think this is the last set of comments and then we can move on 🚀.

src/main.spec.js Outdated
expect(trees[0].children[4].classList.contains("fs-api-file")).toBe(true);
expect(trees[0].children[5].classList.contains("fs-api-file")).toBe(true);

for (const li of trees) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess here you mean const tree of...

src/main.js Outdated
@@ -2,7 +2,15 @@ function convertItemsToUnorderedList(listItems) {
const ulElement = document.createElement("ul");
listItems.forEach(item => {
const liElement = document.createElement("li");
liElement.textContent = item.name;
liElement.classList.add("fs-api-entry");
Copy link
Member

Choose a reason for hiding this comment

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

You can squash these two .add calls into one 😄: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList#Methods

src/main.spec.js Outdated
expect(trees[0].children[3].children[0].textContent).toBe("SFile.sth");
expect(trees[0].children[4].children[0].textContent).toBe("test.go");
expect(trees[0].children[5].children[0].textContent).toBe("Troll.go");
const vendorChildren = trees[0].children[1].children[1];
Copy link
Member

Choose a reason for hiding this comment

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

Is this trees[1]? If yes, we should use this instead.

src/main.spec.js Outdated
expect(ul.children[3].textContent).toBe("SFile.sth");
expect(ul.children[4].textContent).toBe("test.go");
expect(ul.children[5].textContent).toBe("Troll.go");
expect(trees[0].children[0].children[0].textContent).toBe("Dir");
Copy link
Member

Choose a reason for hiding this comment

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

Can we rename trees[0] to something more semantic (e.g. rootTree, mainTree)

Copy link
Member

@parisk parisk left a comment

Choose a reason for hiding this comment

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

Thank you 🎩!

@parisk parisk merged commit 8ea1f1c into sourcelair:master Jul 26, 2018
@irokas irokas deleted the Multiple-levels branch July 26, 2018 10:11
@parisk parisk added this to the 0.2 milestone Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants