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

refactor(): replace indexOf with includes #8784

Merged
merged 1 commit into from Dec 16, 2021

Conversation

zanminkian
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@coveralls
Copy link

Pull Request Test Coverage Report for Build 69ef75a0-16f0-430d-a3fa-53e6acba83a9

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 94.08%

Totals Coverage Status
Change from base Build ae79619d-0b24-423a-a05d-60ade8e7cd73: 0.0%
Covered Lines: 5658
Relevant Lines: 6014

💛 - Coveralls

@jmcdo29
Copy link
Member

jmcdo29 commented Dec 14, 2021

Is there a performance improvement for using includes instead of indexOf?

@zanminkian
Copy link
Contributor Author

Is there a performance improvement for using includes instead of indexOf?

@jmcdo29 No. Just make the intent of the code more clear. See here

@kamilmysliwiec
Copy link
Member

LGTM

@kamilmysliwiec kamilmysliwiec merged commit be6c741 into nestjs:master Dec 16, 2021
@micalevisk
Copy link
Member

@zanminkian what do you think about the following usage of .indexOf

call.on('error', (e: any) => {
// Check if error means that stream ended on other end
const isCancelledError = String(e).toLowerCase().indexOf('cancelled');
if (isCancelledError) {
call.end();
return;
}
// If another error then just pass it along
req.error(e);
});

@zanminkian
Copy link
Contributor Author

@zanminkian what do you think about the following usage of .indexOf

call.on('error', (e: any) => {
// Check if error means that stream ended on other end
const isCancelledError = String(e).toLowerCase().indexOf('cancelled');
if (isCancelledError) {
call.end();
return;
}
// If another error then just pass it along
req.error(e);
});

@micalevisk Is it a bug? I don't have too much time to understand the meaning of the code. So, I refactored some obvious code. Some code I don't understand did not edit it.

@micalevisk
Copy link
Member

I didn't understand that code neither.

I don't know what are the values that e can have but looks like the event is said cancelled if that e is something that doesn't starts with the word 'cancelled'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants