steelbreeze / state.js

DEPRECATED, please see @steelbreeze/state
https://github.com/steelbreeze/state
MIT License
324 stars 39 forks source link

Unexpected current state? #25

Closed withinboredom closed 8 years ago

withinboredom commented 8 years ago

Example:

// create machine
const task = new state.StateMachine('task');

// create psuedo states
const initial = new state.PseudoState('initial', task, state.PseudoStateKind.Initial);
const success = new state.PseudoState('success', task, state.PseudoStateKind.Terminate);
const failure = new state.PseudoState('failure', task, state.PseudoStateKind.Terminate);

// create states
const parsed = new state.State('parsed', task)
    .entry((message, instance) => {
        console.log('parsed');
        instance.parsed = false;
    })
    .exit((message) => console.log('leaving parse'));
const failParse = new state.State('parseFailed', task)
    .entry(() => {
        console.log('failed to parse')
    });

// create transitions
parsed.to(failParse).when((message, instance) => instance.parsed == false);
failParse.to(failure);

// initialize all the things
const instance = new state.StateMachineInstance("instance");
state.initialise(task, instance);
state.evaluate(task, instance);

// output the results
console.log(instance.getCurrent(task.getDefaultRegion()).name);

I'd expect the name of the current state to be failure... however, I'm getting the name failParse though I see it in the output:

instance enter task.default.failure

Am I doing something wrong or is this an actual bug?

withinboredom commented 8 years ago

:facepalm: The state machine does not exit any states ... read the uml spec again ...