javascript-state-machine
javascript-state-machine copied to clipboard
[V3] Lifecycle event name breaks for all uppercase
More more specifically, with more than 1 contiguous uppercase char.
Here's quick repro:
var test = new StateMachine({
init: 'A_BRoken',
transitions: [{
name: 'fail',
from: 'A_BRoken',
to: 'B_Works'
}, {
name: 'pass',
from: 'B_Works',
to: 'A_BRoken'
}],
methods: {
onABroken: (l) => console.log('Enter ABroken'), //never fires
onLeaveABroken: (l) => console.log('Leave ABroken'), //never fires
onBWorks: (l) => console.log('Enter BWorks'),
onLeaveBWorks: (l) => console.log('Leave BWorks'),
},
});
test.fail();
test.pass();
// => Enter BWorks
// => Leave BWorks
For use case context, I was wanting to use my existing enum style of ALL_UPPER for enum values.
Just a suggestion closely related to this: the methods object (which is now called callbacks?) should use camel case naming for the event names. It gets difficult to read something like: onbeforeenterHome. Should be onBeforeEnterHome
This is fixed on the v3 branch (and in upcoming v3.0.1 release). All life cycle event observer methods use camel case, including when state or transition has an ALL_UPPERCASE name.