javascript-state-machine icon indicating copy to clipboard operation
javascript-state-machine copied to clipboard

[V3] Lifecycle event name breaks for all uppercase

Open zachdsawyer opened this issue 9 years ago • 2 comments

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.

zachdsawyer avatar Feb 12 '17 18:02 zachdsawyer

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

juanvillegas avatar May 22 '17 19:05 juanvillegas

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.

jakesgordon avatar Jun 10 '17 18:06 jakesgordon