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

Convert to destructured assignment #693

Open
automatensalat opened this issue Sep 2, 2022 · 2 comments
Open

Convert to destructured assignment #693

automatensalat opened this issue Sep 2, 2022 · 2 comments
Labels
✨ Feature New refactoring or feature

Comments

@automatensalat
Copy link
Contributor

Is this request related to a problem? Please describe.

I often find myself wanting to convert assignments to variables from member expressions to destructurings, like:

// from
const member = parent.member;
// to
const { member } = parent;

Especially if I now want to access another member of the parent object. Unfortunately I didn't find a refactoring for this. Destructure object seems to be for a different usecase.

Describe the solution you'd like

I'd select any part of the assignment (not sure which?) and select a "Convert to destructured assignment" (or so) refactoring. It would retain the variable names, or use the short syntax if it's the same name:

// from
const myMember = parent.member;
// to
const { member: myMember } = parent;
@automatensalat automatensalat added the ✨ Feature New refactoring or feature label Sep 2, 2022
@brunnerh
Copy link

brunnerh commented Jan 7, 2023

Could be accompanied by a command for the inverse operation, creating a line for each member assignment.

@brunnerh
Copy link

brunnerh commented Jan 7, 2023

Also, it would probably be useful if there is a command that can handle multiple members at once.
Not just assignments and not necessarily all in the same place.

Example

// From
const someDialog = new SomeDialog({
  target: order.target,
  props: {
    projectStatus: order.status,
    products: order.products.map(p => ({ ...p })),
    schedules: order.schedules,
  },
});

// To
const { target, status, products, schedules } = order;
const someDialog = new SomeDialog({
  target,
  props: {
    projectStatus: status,
    products: products.map(p => ({ ...p })),
    schedules,
  },
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ Feature New refactoring or feature
Projects
None yet
Development

No branches or pull requests

2 participants