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

Support cross module parsing

Open nicholas570 opened this issue 4 years ago • 6 comments

Config and options have to be written in the same file that declares the machine, to be found by the extension.

Example:

The visualizer can't find the machine ext-import

The visualizer can find the machine ext-no-imports

nicholas570 avatar Jan 11 '22 12:01 nicholas570

Could you expand on why do you want this feature? While some machines might not be loaded now because of that it's an easy refactor. So I assume that your intention is to keep machine configs outside of the createMachine call and I'm wondering why this is important for you.

Andarist avatar Feb 10 '22 14:02 Andarist

Having options outside of the same file as the config is sometimes useful - especially when the config is ~1000 lines long.

mattpocock avatar Feb 11 '22 09:02 mattpocock

And that is already somewhat supported because createMachine doesn't require us to provide implementations right away. As you might suspect I'm just worried about the implications for syncing editor changes to source files if we'd allow this - because I'm worried that the "external" config in this example isn't a single self-contained node.

Andarist avatar Feb 11 '22 09:02 Andarist

Main reason is I'm working with several machines with complex and long config. As Matt said, in this case it's very useful to have options outside. It makes my machines much more readable and makes my development experience much better. Also for new comers, I noticed it was easier to get into machines and behaviors splitting the config and the options.

nicholas570 avatar Feb 12 '22 07:02 nicholas570

It's possible to createMachine in a single file and use machine.withConfig in another. Isn't this sufficient for your needs?

Andarist avatar Feb 12 '22 07:02 Andarist

Yeah it will be fine :)

nicholas570 avatar Feb 12 '22 08:02 nicholas570