You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a rather large state machine (the config is over 1000 lines long) with multiple parallel and parent states. In xstate 4, it was possible to put the definition of the parallel and parent states in separate variables, put everything together in createMachine, and still have strong type safety using typegen. To have strong type safety in xstate 5, the entire configuration must be to be declared in the createMachine function returned by the setup function. For larger machines, this becomes difficult to navigate. That's why I would like to suggest an additional function createStateNodeConfig, which is returned by the setup function. The implementation of the setup function could look like this:
exportfunctionsetup<// unchanged, omitted for better readability>(setupArgs): {// unchanged, replaced in this example with setupArgs for better readability// createMachine omitted for readabilitycreateStateNodeConfig: <TStateNodeConfigextendsStateNodeConfig<TContext,TEvent,ToProvidedActor<TChildrenMap,TActors>,ToParameterizedObject<TActions>,ToParameterizedObject<TGuards>,TDelay,TTag,TOutput,TEmitted,TMeta>>(config: TStateNodeConfig)=>TStateNodeConfig;}{return{// createMachine omitted for readabilitycreateStateNodeConfig: (stateNodeConfig)=>stateNodeConfig};}
This would then allow to define the states like this:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I have a rather large state machine (the config is over 1000 lines long) with multiple parallel and parent states. In xstate 4, it was possible to put the definition of the parallel and parent states in separate variables, put everything together in
createMachine
, and still have strong type safety using typegen. To have strong type safety in xstate 5, the entire configuration must be to be declared in thecreateMachine
function returned by thesetup
function. For larger machines, this becomes difficult to navigate. That's why I would like to suggest an additional functioncreateStateNodeConfig
, which is returned by thesetup
function. The implementation of thesetup
function could look like this:This would then allow to define the states like this:
Full example in typescript playground
Beta Was this translation helpful? Give feedback.
All reactions