Repository navigation
xstate@4.24.0
·
3587 commits
to next
since this release
Minor Changes
-
#2546
a4cfce18cThanks @davidkpiano! - You can now know if an event will cause a state change by using the newstate.can(event)method, which will returntrueif an interpreted machine will "change" the state when sent theevent, orfalseotherwise:const machine = createMachine({ initial: 'inactive', states: { inactive: { on: { TOGGLE: 'active' } }, active: { on: { DO_SOMETHING: { actions: ['something'] } } } } }); const state = machine.initialState; state.can('TOGGLE'); // true state.can('DO_SOMETHING'); // false // Also takes in full event objects: state.can({ type: 'DO_SOMETHING', data: 42 }); // false
A state is considered "changed" if any of the following are true:
- its
state.valuechanges - there are new
state.actionsto be executed - its
state.contextchanges
See
state.changed(documentation) for more details. - its
Patch Changes
-
#2632
f8cf5dfe0Thanks @davidkpiano! - A regression was fixed where actions were being typed asneverif events were specified increateModel(...)but not actions:const model = createModel( {}, { events: {} } ); model.createMachine({ // These actions will cause TS to not compile entry: 'someAction', exit: { type: 'someObjectAction' } });