c-hive / dotdev

Next.js SPA professional website template for teams and individuals: https://c-hive.github.io/dotdev/
MIT License
0 stars 1 forks source link

Fix application error. #130

Closed gomorizsolt closed 4 years ago

gomorizsolt commented 4 years ago

Issue #128 (there's also an explanation).

Let's use early-returns to break renderLanguages().

gomorizsolt commented 4 years ago

Is it just me or is it weird that a function is defined in the middle of the component logic?

I didn't find it weird. Though if it's confusing, let's move it to the top.

gomorizsolt commented 4 years ago

Does !languages necessarily mean an error?

I'd like to avoid looping over falsy values even if there's not much chance of it. We can omit this if it clutters the logic though.

How about an empty repo for example?

Empty repositories return empty objects which means they're converted to empty arrays.

(1) If the repository is empty, once the fetch is fulfilled, data becomes {}.

https://github.com/c-hive/dotdev/blob/de33b7dce3b887563b1ac3bea022c2943356820e/src/components/Projects/utils/GithubUtils.js#L54

(2) Calling the filter() method on an empty object returns an empty array.

https://github.com/c-hive/dotdev/blob/de33b7dce3b887563b1ac3bea022c2943356820e/src/components/Projects/utils/GithubUtils.js#L63

(3) Looping over an empty array with map() is obviously fine.

https://github.com/c-hive/dotdev/blob/de33b7dce3b887563b1ac3bea022c2943356820e/src/components/Projects/ProjectDisplayer/ProjectDisplayer.js#L62-L76

I hope this breakdown answers your question.