-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
There was a problem hiding this 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'; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 }
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better now, thanks :)
LGTM, thanks for the PR! :) |
Hi, I removed axios and replaced it with http. (fetch.ts, api.ts)
and I change somethings...