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

Conversation

@shadoo77
Copy link

No description provided.

remarcmij
remarcmij previously approved these changes Aug 25, 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 Shadi, good work again this week. Some minor comments on naming. See my comment on the second event listener: something to address in the week 3 homework.

const select = createAndAppend('select', header, { id: 'selectMenu' });
// use promise object
const promise = fetchJSON(url);
promise.then(data => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Introducing an intermediate variable promise helps to understand here what fetchJSON() returns. This is a good approach when learning. Later you will use promises all over the place and you will probably not bother to create intermediate variables, but chain directly from the function returning a promise, e.g.

fetchJSON(url)
  .then(data => {
    //...
  })
  .catch(...

Since we know that we are getting a list (i.e. array) of repositories, the code would become a bit more readable if you renamed the generic meaningless name data to repositories. Your code could then read as:

repositories.sort((a, b) => a.name.localeCompare(b.name, 'fr', {ignorePunctuation: true}));
repositories.forEach((repository, index) => {
  createAndAppend('option', select, {html: repository.name, value: index});
});

Note that you could also chain this as:

repositories
  .sort((a, b) => a.name.localeCompare(b.name, 'fr', {ignorePunctuation: true}))
  .forEach((repository, index) => {
    createAndAppend('option', select, {html: repository.name, value: index});
  });

// use promise object
const promise = fetchJSON(url);
promise.then(data => {
data.sort((a, b) => a.name.localeCompare(b.name, 'fr', {ignorePunctuation: true}));
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is from week 1:

You have probably taken the localeCompare arguments from an example in MDN, but there is really reason why should specifically configure it for the French language (argument 'fr').





Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is from week 1:

Use a single blank line between function definitions.



// function who creates a left content section
function contentLeft(container, data, select) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename data to repositories. In general, use generic, meaningless names such as data, info etc only when the variable or parameter can contain anything. When you know, as in this case, exactly what the function parameter will receive, choose a names that accurately describes it contents.

const tr4 = createAndAppend('tr', lTable);
createAndAppend('td', tr4, {html: 'Updated :', class: 'lable'});
const td4 = createAndAppend('td', tr4);
const defaultElDate = repository.updated_at;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a comment from week 1:

Since you are repeating code here (create a tr with two tds as children, you could create a separate function to avoid repetition (the DRY principle: Don't Repeat Yourself), for instance:

  function (table, label, value) {
    const tr = createAndAppend('tr', table);
    createAndAppend('td', tr, { html: `${label} :`, class: 'label' });
    createAndAppend('td', tr, { html: value });
  }



// function who creates a right content section
function contentRight(container, data, select) {
Copy link
Contributor

Choose a reason for hiding this comment

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

data -> contributors

const rightSection = createAndAppend('div', container, { id: 'rightSection', class: 'whiteframe' });
createAndAppend('h5', rightSection, {html: "Contributions :", class: 'contributionsLable'});
const contributorsURL = data[0].contributors_url;
const ContributorsPromise = fetchJSON(contributorsURL);
Copy link
Contributor

Choose a reason for hiding this comment

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

Variable, parameter and function names should be camelCase. Only constructor functions and ES6 classnames should be PascalCase. See the naming convention fundamental.

createAndAppend('div', rightSection, { html: error.message, class: 'alert-error' });
});

select.addEventListener('change', (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You have added a second event listener here. A single event listener that handles both the repository data (left-hand) and contributor data (right-hand) is generally preferred. This simplifies understanding cause and effect in the app, especially for other developers looking at your code. They may not expect a second handler for the same event.

function showContributors(rightSection, contributors) {
contributors.forEach(contributor => {
const contrSection = createAndAppend('section', rightSection);
const contrMainLink = createAndAppend('a', contrSection, {href: contributor.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.

In terms of naming, all these contr prefixes are unnecessary, as in the context of this function everything evolves around contributors.

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