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 idea: Refactor function to module scope, but preserve the function itself (with/out arguments) #37

Closed
aghArdeshir opened this issue Jul 4, 2022 · 2 comments

Comments

@aghArdeshir
Copy link

aghArdeshir commented Jul 4, 2022

Hi. Sometimes I use P42 for refactoring callbacks, so the code would be cleaner, but I always have to make a manual refactor to make it more performant. I want my callbacks to be preserved (instead of me

Initial:
image

Result:
image

Expected:
image

I'm not too familiar with this whole parsing and automatic refactoring thing and I don't know the thing I expect is possible or not. And I'm aware with arguments it will be more and more complicated But I believe the simple cases can be detected and put as an option.

@aghArdeshir aghArdeshir changed the title Refactor idea: Refactor function to module scope, but preserve the function itself (with arguments) Refactor idea: Refactor function to module scope, but preserve the function itself (with/out arguments) Jul 4, 2022
@lgrammel
Copy link
Contributor

lgrammel commented Jul 4, 2022

Hi @aghArdeshir - thanks for the refactoring idea!

I'm unsure which P42 refactoring you are currently using - my guess is that you use an "extract to function in module scope" refactoring from VS Code (which would explain why it's an arrow function wrapped in a function).

With P42, you could use "extract const" as follows:

image

This would give you:

image

It's a bit different from your expected result however, because the extracted function is not at the top level. Is this closer to what you were looking for?

@aghArdeshir
Copy link
Author

Yup. Sorry 👍
THat makes sense

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

No branches or pull requests

2 participants