xstate-tools icon indicating copy to clipboard operation
xstate-tools copied to clipboard

Rename machine event keys when renaming the model's events

Open with-heart opened this issue 3 years ago • 3 comments

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.

with-heart avatar Jan 10 '22 05:01 with-heart

Tasty, that would be great.

mattpocock avatar Jan 10 '22 09:01 mattpocock

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

ivancuric avatar Jun 15 '23 14:06 ivancuric

cc. @Andarist is this possible?

davidkpiano avatar Aug 21 '23 20:08 davidkpiano