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

feature: refactor get the snippet code #1120

Conversation

NguyenTuanCanh
Copy link

Changes made:

  1. Removed unnecessary nested promises by chaining then() calls.
  2. Used forEach loop instead of for loop for iterating over codeLines.
  3. Replaced indexOf with includes for checking if a line contains the search term.
  4. Simplified the logic for setting startingLine and foundLine within the loop.
  5. Replaced arrow functions with concise arrow functions where possible.

Copy link

vercel bot commented Apr 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 5, 2024 9:57am

Comment on lines +107 to +109
.then(response => response.text())
.then(text => {
const parsed = JSON.parse(JSON.parse(text).jsonPayload);
Copy link
Contributor

Choose a reason for hiding this comment

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

would this work?

Suggested change
.then(response => response.text())
.then(text => {
const parsed = JSON.parse(JSON.parse(text).jsonPayload);
.then(response => response.json())
.then(jsonData => {
const parsed = JSON.parse(jsonData.jsonPayload);

Copy link
Author

Choose a reason for hiding this comment

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

@yedpodtrzitko I think keeping my version will work fine. As for yours, I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

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

We should try as it is better ? can you check @NguyenTuanCanh ?

Copy link
Member

Choose a reason for hiding this comment

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

Both should work, one needs one less JSON.parse call.

}
if (line.toLowerCase().includes(lowerTerm)) {
foundLine = index;
startingLine = Math.max(foundLine - 5, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Without the break, the code might not early exit anymore, why this change ?

Copy link
Author

Choose a reason for hiding this comment

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

@sebavan Wow, thank you for your question. Updated!

Copy link
Member

Choose a reason for hiding this comment

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

Your version is still different as foundLine will not be set outside of the condition but was always set in the loop version. I would in this case recommend to keep the loop as there is no reasons not too ?

@RaananW
Copy link
Member

RaananW commented May 3, 2024

This is mainly a cosmetic change, right? No functionality has changed?

@RaananW
Copy link
Member

RaananW commented May 6, 2024

I am a bit confused as to the current changes. Formatting has changed a bit, but it seems like the code as it is is almost (or even completely) the same?

@RaananW
Copy link
Member

RaananW commented Jun 13, 2024

any update here? or should I close it?

@RaananW RaananW closed this Jul 1, 2024
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.

4 participants