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
This issue is for building a codemod that migrates a codebase from v4 to v5. The codemod would analyze the abstract syntax tree (AST) of the codebase in order to identify syntax changes that need to be made and apply those changes.
We'd also need to create a cli to apply the codemod. I can't remember if there's an xstate cli out there already or not, but if so we can reuse it. I'm thinking xstate codemod v4-to-v5 or something like that.
move any non-type properties into new params property object
(context, event)
({context, event})
wrap arguments in object syntax
if the arguments aren't named context and event, we'll need to make sure that the object's keys use the correct names (example: (ctx) becomes ({context: ctx}))
actor.onTransition
actor.subscribe
?
do they have the same interface?
send
raise/sendTo
?
is there a way to tell from send usage which new fn should be used instead?
internal: false
reenter: true
if internal: true, remove property
if internal: false, remove and replace with new reenter: true property
interpret(machine).start(state)
interpret(machine, {state}).start()
remove state argument from start call
create/update 2nd interpret argument object with state property
actor.send('event')
actor.send({type: 'event'})
remove string argument
create object argument with type: 'event' property
null event ('')
always
replace '' key with always
createMachine(config, options)
createMachine(config).provide(options)
remove 2nd argument from createMachine
append call to .provide with options as its argument
machine.withConfig(options, context)
machine.provide({…options, context})
remove .withConfig call
add .provide call
if context is passed
add empty object argument to provide call
spread options in object argument
add context property to object argument
if context is not passed, add options as argument to provide
need to handle cases where both .withConfig and .withContext were called
machine.withContext(context)
machine.provide({context})
remove .withContext call
add .provide call
add object with context property as argument to provide
need to handle cases where both .withConfig and .withContext were called
predictableActionArguments: true
-
remove predictableActionArguments property
strict: true
-
remove strict property
state.history
-
remove state.history property
is there anything else we could do here? maybe notify the user that state.history no longer exists and where it's being used so they can adjust their code?
actor.batch([...])
removed
remove actor.batch call
create an individual actor.send call for each event in the array
is this an appropriate solution?
config.schema
config.types
rename schema key to types
need to make sure this works together with config.tsTypes change
config.tsTypes
config.types.typegen
create types property with empty object value
move tsTypes property to types object
rename tsTypes key to typegen
need to make sure this works together with config.schema change
The text was updated successfully, but these errors were encountered:
This issue is for building a codemod that migrates a codebase from v4 to v5. The codemod would analyze the abstract syntax tree (AST) of the codebase in order to identify syntax changes that need to be made and apply those changes.
We'd also need to create a cli to apply the codemod. I can't remember if there's an
xstate
cli out there already or not, but if so we can reuse it. I'm thinkingxstate codemod v4-to-v5
or something like that.You can find the current (as of 4/14) migration guide here: https://docs-git-davidkpiano-v5-outline-statelyai.vercel.app/xstate-v5/migration
Here's a table of changes to target:
Machine
createMachine
Machine
identifier withcreateMachine
Machine
import withcreateMachine
cond
guard
cond
keys withguard
cond
andactions
objects can have any keytype
andparams
type
properties into newparams
property object(context, event)
({context, event})
context
andevent
, we'll need to make sure that the object's keys use the correct names (example:(ctx)
becomes({context: ctx})
)actor.onTransition
actor.subscribe
send
raise
/sendTo
send
usage which new fn should be used instead?internal: false
reenter: true
internal: true
, remove propertyinternal: false
, remove and replace with newreenter: true
propertyinterpret(machine).start(state)
interpret(machine, {state}).start()
state
argument fromstart
callinterpret
argument object withstate
propertyactor.send('event')
actor.send({type: 'event'})
type: 'event'
property''
)always
''
key withalways
createMachine(config, options)
createMachine(config).provide(options)
createMachine
.provide
withoptions
as its argumentmachine.withConfig(options, context)
machine.provide({…options, context})
.withConfig
call.provide
callcontext
is passedprovide
calloptions
in object argumentcontext
property to object argumentcontext
is not passed, addoptions
as argument toprovide
.withConfig
and.withContext
were calledmachine.withContext(context)
machine.provide({context})
.withContext
call.provide
callcontext
property as argument toprovide
.withConfig
and.withContext
were calledpredictableActionArguments: true
predictableActionArguments
propertystrict: true
strict
propertystate.history
state.history
propertystate.history
no longer exists and where it's being used so they can adjust their code?actor.batch([...])
actor.batch
callactor.send
call for each event in the arrayconfig.schema
config.types
schema
key totypes
config.tsTypes
changeconfig.tsTypes
config.types.typegen
types
property with empty object valuetsTypes
property totypes
objecttsTypes
key totypegen
config.schema
changeThe text was updated successfully, but these errors were encountered: