Open SimonGAndrews opened 2 years ago
The format of state value in fsmPlus could be one of a number of options.
At the risk of not migrating xstate functionality to fsm-plus in line with the xstate conventions, the xstate full path id convention would seem to
Hence the initial version of fsmPlus will use delimited strings for the value property as in "chassie" , "chassie.axel' or 'chassie.engine.block' .
the following code provide the means to return a state config from a state value reference in the full path id convention
// fsmPlus - returns the statenode config object (as defined in fsmConfig) from a given full state ID
// assumes a correctly formatted full state id which exists in the machine
function getStateFromID(id, fsmConfig) {
if (id == null) return null
path = 'states.' + id.slice(id.indexOf('.') + 1).split('.').join('.states.');
return path.split('.').reduce((prev, curr) => prev && prev[curr], fsmConfig);
}
unit test stateMap.test.js is used to test this functionality.
Within an enhancement to add Hierarchical State Nodes to xstate/fsm there is a need to represent the machine state 'value' property in a way than supports Hierarchical state definitions.
In xstate/fsm the 'value' property of a state is a simply string containing the name of the state. eg
In order to support Hierarchical nodes the 'value' property will need to include substates from the machine root state to any given state / substate ie represent a statenode.
The 'value' property has at least two use cases in xstate/fsm:
console.log ( machine.value)
ormachine.transition(initialState,'Event')
whereinitialstate.value
defines the source state for the transition.The scope of this issue is to determine the format of 'value' , provide supporting handling functions and to implement it in the transition function.