fix(deps): update dependency xstate to v5 #240
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains the following updates:
^4.35.0
->^5.0.0
Release Notes
statelyai/xstate (xstate)
v5.9.1
Compare Source
Patch Changes
567267ed2
Thanks @Andarist! - Add missingemit
exportv5.9.0
Compare Source
Minor Changes
#4746
b570ba20d
Thanks @davidkpiano! - The newemit(…)
action creator emits events that can be received by listeners. Actors are now event emitters.#4777
4abeed9df
Thanks @Andarist! - Added support forparams
toenqueueActions
v5.8.2
Compare Source
Patch Changes
9a0120901
Thanks @Andarist! - Fixed a type issue that preventsendParent
to be accepted bysetup
whendelays
stayed not configured.v5.8.1
Compare Source
Patch Changes
4a29f8aab
Thanks @Andarist! - Correctly use falsy outputs (instead of accidentally converting them toundefined
).v5.8.0
Compare Source
Minor Changes
a9e3c086f
Thanks @Andarist! - Revampedsetup
and actions types to disallow usage of non-configured implementationsv5.7.1
Compare Source
Patch Changes
15b7dd1f0
Thanks @devanfarrell! - Removedthis
from machine snapshot methods to fix issues with accessing those methods from union of actors and their snapshots.v5.7.0
Compare Source
Minor Changes
#4290
7a8796f80
Thanks @davidkpiano! - An error will now be thrown if an incompatible state value is passed tomachine.resolveState({ value })
.#4693
11b6a1ae1
Thanks @davidkpiano! - You can now inspect microsteps (@xstate.microstep
) and actions (@xstate.action
):v5.6.2
Compare Source
Patch Changes
#4731
960cdcbcb
Thanks @davidkpiano! - You can now importgetInitialSnapshot(…)
fromxstate
directly, which is useful for getting a mock of the initial snapshot when interacting with machines (or other actor logic) withoutcreateActor(…)
:v5.6.1
Compare Source
Patch Changes
#4728
659efd5c1
Thanks @Andarist! - Fixed compatibility issue of the internal type definitions with TypeScript 5.0#4712
2f1d36a9d
Thanks @davidkpiano! - Ensure thatInteropObservable
andInteropSubscribable
are present in the type definition file.#4694
0b6dff210
Thanks @davidkpiano! - AddUnknownMachineConfig
typev5.6.0
Compare Source
Minor Changes
#4704
78699aef6
Thanks @Andarist! -createActor
will now error if the requiredinput
is not given to it.#4688
14902e17a
Thanks @Andarist! - Theschemas
property insetup(...)
is now passed through to the resulting machine. This property is meant to be used with future developer tooling, and is typed asunknown
for now.Patch Changes
51b844230
Thanks @Andarist! - Fixed compatibility with the upcoming TypeScript 5.4v5.5.2
Compare Source
Patch Changes
#4685
e43eab144
Thanks @davidkpiano! - State IDs that have periods in them are now supported if those periods are escaped.The motivation is that external tools, such as Stately Studio, may allow users to enter any text into the state ID field. This change allows those tools to escape periods in state IDs, so that they don't conflict with the internal path-based state IDs.
E.g. if a state ID of
"Loading..."
is entered into the state ID field, instead of crashing either the external tool and/or the XState state machine, it should be converted by the tool to"Loading\\.\\.\\."
, and those periods will be ignored by XState.v5.5.1
Compare Source
Patch Changes
64ee3959c
Thanks @Andarist! - Fixed compatibility with older versions of integration packages.v5.5.0
Compare Source
Minor Changes
#4596
6113a590a
Thanks @davidkpiano! - IntroducegetNextSnapshot(...)
, which determines the next snapshot for the givenactorLogic
based on the givensnapshot
andevent
.If the
snapshot
isundefined
, the initial snapshot of theactorLogic
is used.Patch Changes
1ae07f5bf
Thanks @Andarist! - Allowevent
in transitions to be narrowed down even when its.type
is defined using a union.v5.4.1
Compare Source
Patch Changes
1f2ccb97c
Thanks @davidkpiano! - Typegen-based types for detecting missing implementations have been removed internally.v5.4.0
Compare Source
Minor Changes
#4616
e8c0b15b2
Thanks @Andarist! -context
factories receiveself
now so you can immediately pass that as part of the input to spawned actors.v5.3.1
Compare Source
Patch Changes
#4597
ae0b05f11
Thanks @davidkpiano! - Update the argument object ofenqueueActions(...)
to include theself
andsystem
properties:v5.3.0
Compare Source
Minor Changes
#4547
8e8d2ba38
Thanks @davidkpiano! - AddassertEvent(...)
to help provide strong typings for events that can't be easily inferred, such as events inentry
andexit
actions, or ininvoke.input
.The
assertEvent(event, 'someType')
function will throw if the event is not the expected type. This ensures that theevent
is guaranteed to have that type, and assumes that the event object has the expected payload (naturally enforced by TypeScript).Patch Changes
97f1cbd5f
Thanks @Andarist! - Fixed an issue with ancestors of the default history target that lie outside of the transition domain being incorrectly entered.v5.2.1
Compare Source
Patch Changes
677fb35b7
Thanks @davidkpiano! - Update README.mdv5.2.0
Compare Source
Minor Changes
#4198
ca58904ad
Thanks @davidkpiano! - IntroducetoPromise(actor)
, which creates a promise from anactor
that resolves with the actor snapshot'soutput
when done, or rejects with the actor snapshot'serror
when it fails.Patch Changes
#4568
a5c55fae2
Thanks @Andarist! - Fixed an issue withspawn
withinassign
not returning a narrowed downActorRef
type on TypeScrip 5.0#4570
c11127336
Thanks @Andarist! - Fixed an issue that caused acomplete
listener to be called instead of theerror
one when the actor was subscribed after being stopped.v5.1.0
Compare Source
Minor Changes
d7f220225
Thanks @davidkpiano! - Internal: abstract the scheduler for delayed events so that it is handled centrally by thesystem
.Patch Changes
80818017b
Thanks @davidkpiano! - Fix higher-level logic for state machine logicv5.0.2
Compare Source
Patch Changes
80b9afbae
Thanks @Andarist! - Fixed definingactors
withinput
withinsetup
.v5.0.1
Compare Source
Patch Changes
5041764b2
Thanks @laurakalbag! - Flag that docs in this repo are deprecated in favour of docs at stately.ai/docs/xstatev5.0.0
Compare Source
Major Changes
d3d6149
: If context types are specified in the machine config, thecontext
property will now be required:d3d6149
: - The third argument ofmachine.transition(state, event)
has been removed. Thecontext
should always be given as part of thestate
.machine.microstep(snapshot, event)
which returns the resulting intermediateMachineSnapshot
object that represents a single microstep being taken when transitioning fromsnapshot
via theevent
. This is theMachineSnapshot
that does not take into account transient transitions nor raised events, and is useful for debugging.state.events
property has been removed from theState
objectstate.historyValue
property now more closely represents the original SCXML algorithm, and is a mapping of state node IDs to their historic descendent state nodes. This is used for resolving history states, and should be considered internal.stateNode.isTransient
property is removed fromStateNode
..initial
property of a state node config object can now contain executable content (i.e., actions):assign()
) will now be executed "in order", rather than automatically prioritized. They will be evaluated after previously defined actions are evaluated, and actions that read fromcontext
will have those intermediate values applied, rather than the final resolved value of allassign()
actions taken, which was the previous behavior.This shouldn't change the behavior for most state machines. To maintain the previous behavior, ensure that
assign()
actions are defined before any other actions.d3d6149
: An error will be thrown if aninitial
state key is not specified for compound state nodes. For example:You will get the error:
d3d6149
: IDs for delayed events are no longer derived from event types so this won't work automatically:Please use explicit IDs:
d3d6149
: RemovedState#toStrings
method.d3d6149
: The machine'scontext
is now restricted to anRecord<string, any>
. This was the most common usage, but now the typings preventcontext
from being anything but an object:If
context
isundefined
, it will now default to an empty object{}
.d3d6149
: Actors are now always part of a "system", which is a collection of actors that can communicate with each other. Systems are implicitly created, and can be used to get and set references to any actor in the system via thesystemId
prop:Any invoked/spawned actor that is part of a system will be able to reference that actor:
Each top-level
createActor(...)
call creates a separate implicit system. In this example example,actor1
andactor2
are part of different systems and are unrelated:d3d6149
:external
property on transitions has been renamed toreenter
d3d6149
: Theinterpreter.onStop(...)
method has been removed. Use an observer instead viaactorRef.subscribe({ complete() { ... } })
instead.d3d6149
: RemovedMachineSnapshot['nextEvents']
.d3d6149
: Renamedmachine.withConfig(...)
tomachine.provide(...)
.d3d6149
: Removed third parameter (context) from Machine's transition method. If you want to transition with a particular context value you should create appropriateMachineSnapshot
usingmachine.resolveState
. So instead of this -machine.transition('green', { type: 'TIMER' }, { elapsed: 100 })
, you should do this -machine.transition(machine.resolveState({ value: 'green', context: { elapsed: 100 } }), { type: 'TIMER' })
.d3d6149
: Sending a string event toactorRef.send('some string')
will now throw a proper error message.d3d6149
: Theself
actor reference is now available in all action metas. This makes it easier to reference the "self"ActorRef
so that actions such assendTo
can include it in the event payload:d3d6149
:isState
/isStateConfig
were replaced byisMachineSnapshot
. Similarly,AnyState
type was deprecated and it's replaced byAnyMachineSnapshot
type.d3d6149
: All actor snapshots now have a consistent, predictable shape containing these common properties:status
:'active' | 'done' | 'error' | 'stopped'
output
: The output data of the actor when it has reachedstatus: 'done'
error
: The error thrown by the actor when it has reachedstatus: 'error'
context
: The context of the actorThis makes it easier to work with actors in a consistent way, and to inspect their snapshots.
d3d6149
: Restoring persisted state is now done by passing the state into thesnapshot: ...
property of thecreateActor
options argument:The persisted snapshot is obtained from an actor by calling
actor.getPersistedSnapshot()
:d3d6149
: - Theexecute
option for an interpreted service has been removed. If you don't want to execute actions, it's recommended that you don't hardcode implementation details into the basemachine
that will be interpreted, and extend the machine'soptions.actions
instead. By default, the interpreter will execute all actions according to SCXML semantics (immediately upon transition).xstate/devTools/redux
:By default, dev tools are attached to the global
window.__xstate__
object:And creating your own custom dev tools adapter is a function that takes in the
actorRef
:These handlers have been removed, as they are redundant and can all be accomplished with
.onTransition(...)
and/or.subscribe(...)
:actorRef.onEvent()
actorRef.onSend()
actorRef.onChange()
The
actorRef.send(...)
method no longer returns the next state. It is avoid
function (fire-and-forget).The
actorRef.sender(...)
method has been removed as redundant. UseactorRef.send(...)
instead.d3d6149
: The output data on final states is now specified as.output
instead of.data
:d3d6149
: Support for getters as a transition target (instead of referencing state nodes by ID or relative key) has been removed.The
Machine()
andcreateMachine()
factory functions no longer support passing incontext
as a third argument.The
context
property in the machine configuration no longer accepts a function for determining context (which was introduced in 4.7). This might change as the API becomes finalized.The
activities
property was removed fromState
objects, as activities are now part ofinvoke
declarations.The state nodes will not show the machine's
version
on them - theversion
property is only available on the root machine node.d3d6149
: Thein: ...
property for transitions is removed and replaced with guards. It is recommended to usestateIn()
andnot(stateIn())
guard creators instead:d3d6149
: RemovedActor['status']
from publicly available properties.d3d6149
: All builtin action creators (assign
,sendTo
, etc) are now returning functions. They exact shape of those is considered an implementation detail of XState and users are meant to only pass around the returned values.d3d6149
: Autoforwarding events is no longer supported and theautoForward
property has been removed.Instead of autoforwarding, events should be explicitly sent to actors:
d3d6149
: The machine.schema
property is now.types
:And the
.tsTypes
property is now.types.typegen
:d3d6149
: Returning promises when creating a callback actor doesn't work anymore. Only cleanup functions can be returned now (orundefined
).d3d6149
: There is now support for higher-level guards, which are guards that can compose other guards:and([guard1, guard2, /* ... */])
returnstrue
if all guards evaluate to truthy, otherwisefalse
or([guard1, guard2, /* ... */])
returnstrue
if any guard evaluates to truthy, otherwisefalse
not(guard1)
returnstrue
if a single guard evaluates tofalse
, otherwisetrue
d3d6149
: The.send(...)
method onactorRef.send(...)
now requires the first argument (the event to send) to be an object; that is, either:{ type: 'someEvent' }
)The second argument (payload) is no longer supported, and should instead be included within the object:
d3d6149
: Actions and guards that follow eventless transitions will now receive the event that triggered the transition instead of a "null" event ({ type: '' }
), which no longer exists:d3d6149
: You can now add asystemId
to spawned actors to reference them anywhere in the system.d3d6149
: Reading the initial state from an actor viaactorRef.initialState
is removed. UseactorRef.getSnapshot()
instead.d3d6149
:machine.initialState
has been removed, you can usemachine.getInitialState(...)
insteadd3d6149
: Target resolution improvements: targeting sibling nodes from the root is no longer valid, since the root node has no siblings:d3d6149
: ThecreateActor(...)
function now acceptsinput
in the second argument, which passes input data in the"xstate.init"
event:d3d6149
: Invoked actors can now be deeply persisted and restored. When the persisted state of an actor is obtained viaactorRef.getPersistedSnapshot()
, the states of all invoked actors are also persisted, if possible. This state can be restored by passing the persisted state into thesnapshot: ...
property of thecreateActor
options argument:d3d6149
: Atomic and parallel states should no longer be reentered when the transition target doesn't escape them. You can get the reentering behavior by configuringreenter: true
for the transition.d3d6149
: Restored state will no longer contain actions, since they are assumed to have already been executed. Actions will not be replayed.If you want to replay actions when restoring state, it is recommended to use an event sourcing approach.
d3d6149
: Thein: '...'
transition property can now be replaced withstateIn(...)
andstateNotIn(...)
guards, imported fromxstate/guards
:The
stateIn(...)
andstateNotIn(...)
guards also can be used the same way assnapshot.matches(...)
:An error will now be thrown if the
assign(...)
action is executed when thecontext
isundefined
. Previously, there was only a warning.Error events raised by the machine will be thrown if there are no error listeners registered on an actor via
actorRef.subscribe({ error: () => {} })
.d3d6149
: Action/actor/delay/guard arguments are now consolidated into a single object argument. This is a breaking change for all of those things that are called with arguments.d3d6149
: Eventless transitions must now be specified in thealways: { ... }
object and not in theon: { ... }
object:d3d6149
: Removed the ability to pass a string value directly toinvoke
. To migrate you should use the object version ofinvoke
:d3d6149
:machine.transition(...)
andmachine.getInitialState(...)
require now anactorScope
argumentd3d6149
: All events automatically generated by XState will now be prefixed byxstate.
. Naming scheme changed slightly as well, for exampledone.invoke.*
events becamexstate.done.actor.*
events.d3d6149
: Theescalate()
action is removed. Just throw an error normally.d3d6149
: Theactor.onTransition(...)
method has been removed in favor of.subscribe(...)
d3d6149
: Observing an actor viaactorRef.subscribe(...)
no longer immediately receives the current snapshot. Instead, the current snapshot can be read fromactorRef.getSnapshot()
, and observers will receive snapshots only when a transition in the actor occurs.d3d6149
: Actors can no longer be stopped directly by calling. They can only be stopped from its parent internally (which might happen when you useactor.stop()
stop
action or automatically when a machine leaves the invoking state). The root actor can still be stopped since it has no parent.d3d6149
: ThematchState(...)
helper function is removed.d3d6149
: Parameterized actions now require aparams
property:d3d6149
: The history resolution algorithm has been refactored to closely match the SCXML algorithm, which changes the shape ofstate.historyValue
to map history state node IDs to their most recently resolved target state nodes.d3d6149
: Custom action objects and guard objects are now expected to put extra parameters on theparams
property:d3d6149
: Thestrict: true
option for machine config has been removed.d3d6149
: Removed the ability to define delayed transitions using an array. Only object variant is supported now:d3d6149
: RemovedState['transitions']
.d3d6149
: Removed the deprecatedsend
action creator. Please usesendTo
when sending events to other actors orraise
when sending to itself.d3d6149
: ThecreateEmptyActor()
function has been added to make it easier to create actors that do nothing ("empty" actors). This is useful for testing, or for some integrations such asuseActor(actor)
in@xstate/react
that require an actor:d3d6149
:machine.transition
no longer accepts state values. You have to resolve the state value to aState
before passing it tomachine.transition
d3d6149
: RemoveddeferEvents
from the actor options.d3d6149
: Thestate.history
property has been removed. This does not affect the machine "history" mechanism.Storing previous state should now be done explicitly:
d3d6149
: All errors caught while executing the actor should now consistently include the error in itssnapshot.error
and should be reported to the closesterror
listener.d3d6149
: You can now import the following fromxstate
:The
send
action was removed from exports; usesendTo(...)
orraise(...)
instead.d3d6149
: BREAKING: Thecond
property in transition config objects has been renamed toguard
. This unifies terminology for guarded transitions and guard predicates (previously called "cond", or "conditional", predicates):d3d6149
: TheMachine()
function has been removed. Use thecreateMachine()
function instead.d3d6149
: Theinterpreter.onError(...)
method has been removed. Useinterpreter.subscribe({ error(err) => { ... } })
instead.d3d6149
: Actions are no longer called withstate
d3d6149
:spawn
is no longer importable fromxstate
. Instead you get it inassign
like this:In addition to that, you can now
spawn
actors defined in your implementations object, in the same way that you were already able to do that withinvoke
. To do that just reference the defined actor like this:d3d6149
:State
class has been removed and replaced byMachineSnapshot
object. They largely have the same properties and methods. On of the main noticeable results of this change is that you can no longer checkstate instanceof State
.d3d6149
: Guard arguments are now consolidated into a single object argument. This is a breaking change for all guards that are called with arguments.d3d6149
: Theservice.batch(events)
method is no longer available.d3d6149
: TheStateSchema
type has been removed from all generic type signatures.d3d6149
: RemovedState['_internalQueue']
.d3d6149
:EmittedFrom
type helper has been renamed toSnapshotFrom
.d3d6149
: ThefromReducer(...)
function is now calledfromTransition(...)
.d3d6149
: Thepure()
andchoose()
action creators have been removed, in favor of the more flexibleenqueueActions()
action creator:d3d6149
: Changed behavior ofalways
transitions. Previously they were always selected after selecting any transition (including thealways
transitions). Because of that it was relatively easy to create an infinite loop using them.Now they are no longer selected if the preceeding transition doesn't change the state of a machine.
d3d6149
: Breaking: Thestate.children
property is now a mapping of invoked actor IDs to theirActorRef
instances.Breaking: The way that you interface with invoked/spawned actors is now through
ActorRef
instances. AnActorRef
is an opaque reference to anActor
, which should be never referenced directly.Breaking: The
origin
of anSCXML.Event
is no longer a string, but anActorRef
instance.d3d6149
: Theservices
option passed as the second argument tocreateMachine(config, options)
is renamed toactors
. Each value inactors
should be a function that takes incontext
andevent
and returns a [behavior](TODO: link) for an actor. The provided behavior creators are:fromMachine
fromPromise
fromCallback
fromObservable
fromEventObservable
d3d6149
: The error event (type: 'xstate.error.*'
) now has the error data on theevent.error
instead ofevent.data
:d3d6149
:_event
has been removed from all APIs and types. It was a wrapper structure containing theevent
that users were using directly.d3d6149
: Actor types can now be specified in the.types
property ofcreateMachine
:d3d6149
:Interpreter['off']
method has been removed.d3d6149
:.nextState
method has been removed from theInterpreter
.State#can
can be used to check if sending a particular event would lead to a state change.d3d6149
: Support for compound string state values has been dropped from Machine's transition method. It's no longer allowed to call transition like this -machine.transition('a.b', { type: 'NEXT' })
, instead it's required to use "state value" representation like this -machine.transition({ a: 'b' }, { type: 'NEXT' })
.d3d6149
: - Breaking: activities removed (can be invoked)Since activities can be considered invoked services, they can be implemented as such. Activities are services that do not send any events back to the parent machine, nor do they receive any events, other than a "stop" signal when the parent changes to a state where the activity is no longer active. This is modeled the same way as a callback service is modeled.
d3d6149
: Removed previously deprecated config properties:onEntry
,onExit
,parallel
andforward
.d3d6149
: Thestate._sessionid
property has been removed. It should be obtained directly from the actor:actor.sessionId
.d3d6149
: Thesystem
can now be accessed in all available actor logic creator functions:d3d6149
: Typings forTypestate
have been removed. The reason for this is that types for typestates needed to be manually specified, which is unsound because it is possible to specify impossible typestates; i.e., typings for a state'svalue
andcontext
that are impossible to achieve.d3d6149
: Theactor.onDone(...)
method is removed. Useactor.subscribe({ complete() {... } })
instead.d3d6149
: ThecreateModel()
function has been removed in favor of relying on strong types in the machine configuration.d3d6149
:sync
option has been removed frominvoke
andspawn
.d3d6149
: RemovedState['event']
.d3d6149
: The finaloutput
of a state machine is now specified directly in theoutput
property of the machine config:Configuration
📅 Schedule: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR has been generated by Mend Renovate. View repository job log here.