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

Rename machine event keys when renaming the model's events #30

Open
with-heart opened this issue Jan 10, 2022 · 3 comments
Open

Rename machine event keys when renaming the model's events #30

with-heart opened this issue Jan 10, 2022 · 3 comments
Assignees

Comments

@with-heart
Copy link
Contributor

with-heart commented Jan 10, 2022

When renaming events on a model (Rename Symbol / F2), VSCode doesn't rename the corresponding event keys in the machine defintion.

This would be a nice quality-of-life improvement when using createModel.

Example

import {createMachine} from 'xstate'
import {createModel} from 'xstate/lib/model'

const model = createModel(
  {
    name: 'Matt',
  },
  {
    events: {
      nameChange: (name: string) => ({name}),
    },
  },
)

const machine = model.createMachine(
  {
    on: {
      nameChange: {actions: 'setName'},
    },
  },
  {
    actions: {
      setName: model.assign(
        {
          name: (_context, event) => event.name,
        },
        'nameChange',
      ),
    },
  },
)

Using the VSCode Rename Symbol feature on nameChange inside the model definition should also rename the event key inside the on definition and in the second argument to model.assign.

@mattpocock
Copy link
Contributor

Tasty, that would be great.

@ivancuric
Copy link

Surprised that this doesn't work, while "go to definition" does!

@davidkpiano
Copy link
Member

cc. @Andarist is this possible?

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

5 participants