Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Conversation

@whitepiolin
Copy link

No description provided.

remarcmij
remarcmij previously approved these changes Sep 3, 2018
Copy link
Contributor

@remarcmij remarcmij left a comment

Choose a reason for hiding this comment

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

Hi @whitepiolin, overall pretty good work. Check again the correct order of .catch() and .then() methods in a promise chain (see the link provided in the detail comment).

const repoSelect = createAndAppend("select", divSelect);
const divFlex = createAndAppend("section", root);
const divInfo = createAndAppend("article", divFlex, { id: "divInfo" });
const divCont = createAndAppend("article", divFlex, { id: "divCont" });
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. Lines 33-44 are best placed inside the main() function, at the beginning, just before the call to fetchJSON(). This will ensure that this code is executed after the web page has been fully loaded. If you place it outside any function like you do here there is a change, for instance, that the div with an id of root hasn't been created in the DOM yet. In that case your code will fail.

  2. I like that you are using semantic HTML tags here instead of just div tag. It reminds me that I should do this more often myself 😉.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

const trForks = createAndAppend("tr", tBody);
createAndAppend("td", trForks, { html: "Forks : " });
const tdForksLink = createAndAppend("td", trForks, );
const linkForks = createAndAppend('a', tdForksLink, { html: repository.forks, href: repository.forks_url });
Copy link
Contributor

Choose a reason for hiding this comment

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

The linkForks variable is unused.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

const trRepository = createAndAppend("tr", tBody);
createAndAppend("td", trRepository, { html: "Repository : " });
const tdRepoLink = createAndAppend("td", trRepository, );
const linkRepository = createAndAppend('a', tdRepoLink, { html: repository.name, href: repository.html_url });
Copy link
Contributor

Choose a reason for hiding this comment

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

The linkRepository variable is unused (you can probably see in VSCode a wavy underline on the variable warning about this). You should only define variables if you have a need for them, otherwise they just become noise.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

return;
})
.then(repositories => {
repositories.forEach((repository, index) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The assignment asked for the list of repositories to be sorted alphabetically.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

createAndAppend('pre', root, { html: JSON.stringify(data, null, 2) });
const HYF_REPOS_URL = 'https://api.github.com/orgs/HackYourFuture/repos?per_page=100';
const root = document.getElementById('root');
createAndAppend("img", root, { src: "./hyf.png", id: "imgLogo" });
Copy link
Contributor

Choose a reason for hiding this comment

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

This HYF logo is the least important to have in UI but takes up the most prominent place on the web page. It pushes the relevant content down. So, not a JavaScript issue, but more of a UX (User Experience) issue. Make sure that you use screen space (we sometimes call it screen real-estate) in the most effective way.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

.catch(error => {
const divError = createAndAppend("container", root, { id: "divError" });
divError.innerHTML = "";
divError.innerHTML = error;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think @JawharBairakdar already pointed to line 51 serving no purpose in the week 1 review.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

function main(HYF_REPOS_URL) {

fetchJSON(HYF_REPOS_URL)
.catch(error => {
Copy link
Contributor

Choose a reason for hiding this comment

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

The .catch() method should (almost) always be placed as the last method in the promise chain. See the link to the fundamental on promises below. When I force an error by tweaking the url a bit I can see that you are rendering the error in the UI but I also see this error message in the console:

index.js:56 Uncaught (in promise) TypeError: Cannot read property 'forEach' of undefined
    at fetchJSON.catch.then.repositories (index.js:56)

After the catch() method is executed the JavaScript runtime happily continues executing the next .then() in the chain, which gets the value of undefined for its repositories parameter. That is why you a complaint about trying to use forEach of undefined.

https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/promises.md#promise-chaining

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

createAndAppend('h2', divCont, { html: "Contributions", class: "h2" });

fetchJSON(repository.contributors_url)
.catch(error => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This catch() should go to the end of the chain.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

fetchJSON(repository.contributors_url)
.catch(error => {
createAndAppend('div', root, { html: error.message, class: 'alert-error' });
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

This return is useless. It just return from the arrow function passed to catch(). It would return anyway on the ending curly brace.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

const divError = createAndAppend("container", root, { id: "divError" });
divError.innerHTML = "";
divError.innerHTML = error;
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

This return is useless. It just return from the arrow function passed to catch(). It would return anyway on the ending curly brace.

Copy link
Author

Choose a reason for hiding this comment

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

Corrected

Copy link
Contributor

@remarcmij remarcmij left a comment

Choose a reason for hiding this comment

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

Looks good! (but still think the logo needs to go or placed elsewhere).

@remarcmij remarcmij closed this Oct 14, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants