Minor Changes
-
#2546
a4cfce18c
Thanks @davidkpiano! - You can now know if an event will cause a state change by using the newstate.can(event)
method, which will returntrue
if an interpreted machine will "change" the state when sent theevent
, orfalse
otherwise: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.value
changes - there are new
state.actions
to be executed - its
state.context
changes
See
state.changed
(documentation) for more details. - its
Patch Changes
-
#2632
f8cf5dfe0
Thanks @davidkpiano! - A regression was fixed where actions were being typed asnever
if 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' } });