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

Remove side effect from array.some callback #184919

Merged

Conversation

CGNonofr
Copy link
Contributor

some method callback is supposed to be side-effect free. Also, findIndex is now well supported

@mjbvz mjbvz assigned Tyriar and unassigned mjbvz Jun 12, 2023
Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

The change looks good, but I'm missing where the side effect is?

@Tyriar Tyriar added this to the June 2023 milestone Jun 12, 2023
@CGNonofr
Copy link
Contributor Author

The index variable is declared outside of the callback and modified inside the callback

Copy link
Member

@Tyriar Tyriar left a comment

Choose a reason for hiding this comment

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

Oh I thought you meant _getTerminalObjectIndexById has a side effect. I wouldn't call .some setting some value outside it's callback a problem, it's basically the same thing as doing it with a for loop. Regardless, the code looks better with your changes so thanks 🙂

@CGNonofr
Copy link
Contributor Author

Oh I thought you meant _getTerminalObjectIndexById has a side effect. I wouldn't call .some setting some value outside it's callback a problem, it's basically the same thing as doing it with a for loop. Regardless, the code looks better with your changes so thanks slightly_smiling_face

It's a problem it you want to tree-shake the code and expect calls to some to be side-effect free

@Tyriar Tyriar merged commit a656c21 into microsoft:main Jun 13, 2023
6 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants