Skip to content
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

One less dependency! #14

Merged
merged 3 commits into from
Oct 5, 2022
Merged

One less dependency! #14

merged 3 commits into from
Oct 5, 2022

Conversation

FelipeIzolan
Copy link
Contributor

Hi, I removed axios and replaced it with http. (fetch.ts, api.ts)
and I change somethings...

Copy link
Owner

@Balastrong Balastrong 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 for the PR!

There are some interesting changes but I'd like to get more insights of your reasons behind them before approving :)

@@ -1,8 +1,9 @@
import axios from 'axios';
import fetch from './fetch';
Copy link
Owner

Choose a reason for hiding this comment

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

Is there any particular reason why reimplementing fetch and not using the native fetch method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

because native fetch not is in node LTS version. (only 17.5^)

src/uti.ts Outdated
Comment on lines 22 to 32
let games: Game[] = [];
const archives = await getChessComArchives(chessUsername);

for (const archive of archives) {
const gamesInArchive = await getChessComGames(archive);
if (gamesInArchive.length > 0) {
games.push(...gamesInArchive.reverse());
}

if (games.length >= amount) {
return games.slice(0, amount);
if (games.length < amount) {
const gamesInArchive = await getChessComGames(archive);
games = [...games, ...gamesInArchive.reverse()];
}
}

return games;
return games.slice(0, amount);
Copy link
Owner

Choose a reason for hiding this comment

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

This actually changes the logic, we previously looked for max 5 archives and return early, now you loop through all archives in any case.

Is there a particular reason for this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to break the loop XD

for (const archive of archives) {
   if (games.length < amount) {
      const gamesInArchive = await getChessComGames(archive);
      games = [...games, ...gamesInArchive.reverse()];
   } else { break }
}

Copy link
Owner

Choose a reason for hiding this comment

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

Looks better now, thanks :)

@Balastrong Balastrong self-requested a review October 5, 2022 06:15
@Balastrong
Copy link
Owner

LGTM, thanks for the PR! :)

@Balastrong Balastrong merged commit 8cd5352 into Balastrong:main Oct 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants