jakesgordon / javascript-state-machine

A javascript finite state machine library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

conditional transitions break the visualisation

bonduell opened this issue · comments

if i try to use transitions like { name : 'goto', from: 'A' to: newState => newState) - visualisation doesn't work as expected.

a little fix can improve this ->

dotcfg.transitions = function(config, options) {
let init = config.init,
transitions = config.options.transitions || [], // easier to visualize using the ORIGINAL transition declarations rather than our run-time mapping
output = [];

if (options.init && init.active) {
    dotcfg.transition(init.name, init.from, init.to, init.dot, config, options, output)
}

transitions.forEach(transition => {
    let to = typeof (transition.to) === 'function' ? transition.to() : transition.to;
    to && dotcfg.transition(transition.name, transition.from, to, transition.dot, config, options, output);
})

return output;

}