Releases: statelyai/xstate
@xstate/[email protected]
Minor Changes
-
7367de2
#946 Thanks @Andarist! - Added a second, optional,options
parameter to thecreateMachine
. Currently onlyactions
map can be put there - similarly how this can be done forxstate
itself:Example
const machine = createMachine({ initial: 'idle' states: { idle: { on: { LOAD: { target: 'loading', actions: 'fetchData' } } }, loading: { // ... } } }, { actions: { fetchData: () => /* ... */ } })
-
3c10215
#811 Thanks @ghengeveld! - Aconfig
property got exposed on created machines. It's the same object which got passed in as argument.
Patch Changes
[email protected]
Patch Changes
- dae8818: Typestates are now propagated to interpreted services.
@xstate/[email protected]
@xstate/[email protected]
Minor Changes
- 3cda398: The
assign()
action creator is now strongly-typed, and takes the context and event types as generic parameters, just like in XState core. - 61ccfbd: Make
interpret
default forTEvent
type parameter more strict. It's nowEventObject
instead ofany
and it matches the default oncreateMachine
.
Patch Changes
- 15fc24c: Export
Typestate
type.
[email protected]
Patch Changes
- 6b3d767: Fixed issue with delayed transitions scheduling a delayed event for each transition defined for a single delay.
@xstate/[email protected]
v4.7.0
- 🐌 If a subscriber/listener subscribes to a service that is already running, it will now receive the current state upon subscription. #814
- 🆙 The new
escalate()
action creator escalates custom error events to a parent machine, which can catch those in theonError
transition:
import { createMachine, actions } from 'xstate';
const { escalate } = actions;
const childMachine = createMachine({
// ...
// This will be sent to the parent machine that invokes this child
entry: escalate({ message: 'This is some error' })
});
const parentMachine = createMachine({
// ...
invoke: {
src: childMachine,
onError: {
actions: (context, event) => {
console.log(event.data);
// {
// type: ...,
// data: {
// message: 'This is some error'
// }
// }
}
}
}
});
- ❓ You can now specify
undefined
as the first argument formachine.transition(...)
, which will default to the initial state:
lightMachine.transition(undefined, 'TIMER').value;
// => 'yellow'
-
🤝 Services (invoked machines) are now fully subscribable and can interop with libraries that implement TC39 Observbles like RxJS. See https://xstate.js.org/docs/recipes/rxjs.html for more info.
-
🆔 When a service is invoked, it has a uniquely generated
sessionId
, which corresponds to_sessionid
in SCXML. This ID is now available directly on the state object to identify which service invocation the state came from:state._sessionid
#523 -
⚙️ The original
config
object passed toMachine(config)
(orcreateMachine(config)
) is now the exact same object reference in the resultingmachine.config
property. -
🎰 The
createMachine()
factory function now exists and is largely the same asMachine()
, except with a couple differences:- The generic type signature is
<TContext, TEvent, TState>
instead of<TContext, TStateSchema, TEvent>
. - There is no third argument for specifying an initial
context
. Use.withContext(...)
on the machine or return a machine with the expectedcontext
in a factory instead.
- The generic type signature is
-
🛑 Event sent to a stopped service will no longer execute any actions, nor have any effect. #735
-
🚸 The invoked actors are now directly available on
state.children
. -
✍️ Plain strings can now be logged in the
log()
action creator:
entry: log('entered here', 'some label')
- 🚄 Transitions are now available on
state.transitions
, which is an array of transition objects that detail exactly which transitions were enabled to transition to this state. This will be ignored in serialization. - ⏩ New action creator:
forwardTo()
https://xstate.js.org/docs/guides/actions.html#forward-to-action - ➕ Assigners now have a third
meta
argument passed in, which contains meta data such as thestate
and the originalaction
- *️⃣ New event type: the wildcard! https://xstate.js.org/docs/guides/transitions.html#wildcard-descriptors
const quietMachine = Machine({
id: 'quiet',
initial: 'idle',
states: {
idle: {
on: {
WHISPER: undefined,
// On any event besides a WHISPER, transition to the 'disturbed' state
'*': 'disturbed'
}
},
disturbed: {}
}
});
quietMachine.transition(quietMachine.initialState, 'WHISPER');
// => State { value: 'idle' }
quietMachine.transition(quietMachine.initialState, 'SOME_EVENT');
// => State { value: 'disturbed' }
- 📲 New action creator:
respond()
https://xstate.js.org/docs/guides/actions.html#respond-action - ✅ New typechecking feature: Typestates https://xstate.js.org/docs/guides/typescript.html#typestates-coming-soon
- 📄 SCXML event metadata is now available on
state._event
and also in action/guard/etc. meta under_event
. https://www.w3.org/TR/scxml/#InternalStructureofEvents
v4.6.7
- A regression in the new
stateUtils.ts
file caused a bundling failure; this is now fixed.
v4.6.6
- A configuration change that included testing files as an included path in
tsconfig.json
was reverted.
v4.6.5
Improvements