Xstate: machine.getState() doesn't exist

Created on 28 Aug 2018  路  3Comments  路  Source: davidkpiano/xstate

Bug

Description:

Machine method getState() as listed in docs doesn't exist. See codepen.

Expected result:

Return a stateNode.

Actual result:

Uncaught error, message: standardMachine.getState is not a function

Most helpful comment

In V4 this will be:

myMachine.getStateNode('foo'); // retrieves myMachine.states.foo
myMachine.getStateNode('#someStateID'); // retrieves (nested?) state with id: someStateId

// alternatively:
myMachine.getStateNodeById('someStateId'); // same as above

myMachine.getStateNodeByPath('foo.bar.baz'); // retrieves nested state with path ['foo', 'bar', 'baz']
myMachine.getStateNodeByPath(['foo', 'bar', 'baz']); // same as above

This is to disambiguate a "State" and "StateNode", which are two different things.

All 3 comments

Hi @bradwoods , this feature was added here and is going to be released in version 3.4.

In V4 this will be:

myMachine.getStateNode('foo'); // retrieves myMachine.states.foo
myMachine.getStateNode('#someStateID'); // retrieves (nested?) state with id: someStateId

// alternatively:
myMachine.getStateNodeById('someStateId'); // same as above

myMachine.getStateNodeByPath('foo.bar.baz'); // retrieves nested state with path ['foo', 'bar', 'baz']
myMachine.getStateNodeByPath(['foo', 'bar', 'baz']); // same as above

This is to disambiguate a "State" and "StateNode", which are two different things.

This is now in master and the latest xstate@next.

Was this page helpful?
0 / 5 - 0 ratings