-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
Convert sequence of independent variables to an object #362
Comments
Interesting. I don't have a strong feeling on this one so far. I'll leave this one open though, so other people can chime in and add their thoughts. If that's something you'd like over other refactorings, please tell me 😄 |
How hard do you think it would be to convert function arguments to/from (destructured) objects as well? Relates to #341 |
@qpwo great question. For the refactoring presented here, most of the things are local to the file, so it shouldn't be too hard to retrieve the bindings of the variables and convert them. I'm also thinking about exported variables. If one of the selected variables is exported (at the declaration or later), we need to detect that to either prevent the refactoring (could be the first iteration) or handle it. Now re-ordering function arguments (#341) and changing them have more or less the same difficulty: we need to update code across the project. Again, a first iteration could make it work for non-exported functions only. But I suspect that will quickly limit the interest. Current refactorings work within the scope of a single file. Or extracting things to other files. |
Thanks for all your work on this project Nicolas |
Re:
Just occured to me a simpler way of phrasing this , and a more useful and general and simpler feature would be Destructure/restructure object
Maybe that should be a separate issue though |
Forgot to put an example with a function: // destructured
function Card({x, y, color}: {x: number, y: number, color: string) {
return <p style={{left: x, top: y, backgroundColor: color}}>{color}</p>
}
// restructured
function Card(props: {x: number, y: number, color: string) {
return <p style={{left: props.x, top: props.y, backgroundColor: props.color}}>{props.color}</p>
} |
Is this request related to a problem? Please describe.
I'm always frustrated when I'm converting global-variable-based code to functionalish code and I have to manually pack global variables into an object. Sometimes a function's internal variable will shadow the global, so I can't just replace-all
foo
toobj.foo
.Describe the solution you'd like
I'd like to select them and convert to an object and update all references correctly.
The text was updated successfully, but these errors were encountered: