order of states
Citate : The machine will transition into the initial state (the first attached stateObject) immediately.
In Javascript order of object properties is not guaranted. For exact order must be array used, isn't it ? So, instead
{ stateX:{...}, stateY:{...} }
it will be something like
[ { state:"X", params: {...} }, { state:"Y", params:{...} } ]
That is correct, the order of object properties isn't guaranteed, although it seems to work in all major browsers and even node.js.
If there is an problem with the initial state on some platforms, I'd rather extend the current implementation with an optional parameter to refer to the expected init state.
@supipd have you got any examples where it was out of order? what engine was it on?
I've never seen it get out of order (in node.js), and I don't think the array approach is workable, or desirable.
V8 and Javascript Gotchas 4.3 Other minor gotchas http://book.mixu.net/ch4.html
I know what you mentioned is technically correct, but I asked if you'd actually seen it yourself? Please re-open this ticket (with details) if you have.
As @fschaefer mentioned, it doesn't seem to be an issue in practice. Until we know it is an issue that is causing people pain, I don't see any reason to spend large amounts of effort on it.
OK, I accept closing this ticket, this is only last tearfull reaction. Most of modules and libraries (commercial too) I tried had minor or major bugs which can cause total crash of application, Today, when realtime, fullfeatured application in-browser (or nodejs) are IN, crashing due to "... its only web, simple restart, or use another, or ... " is not very pleasant. And user has full rights to throw tomatoes to us.
What needs more efforts ... solving problem from people, who knows source code to details, or study, debug, and correct another's work ?
Thanks @fschaefer for more correct reaction.
So, code, and views (V8 in nodejs (GoogleChrome too)):
var Stately = require('./stately.js');
console.log("Let's go on");
var stObj = {
'1': { //logical state LOG1 ... device in ON state
on: function() { console.log("going ON"); return this[1]; }
, off: function() { console.log("going OFF"); return this[0]; }
, err: function() { console.log("going ERR"); return this[2]; }
}
, '0': { //logical state LOG0 ... device in OFF state
on: function() { console.log("going ON"); return this[1]; }
, off: function() { console.log("going OFF"); return this[0]; }
, err: function() { console.log("going ERR"); return this[2]; }
}
, '2':{ //logical state ERR ... device in ERROR or UNKNOWN state
on: function() { console.log("going ON"); return this[1]; }
, off: function() { console.log("going OFF"); return this[0]; }
, err: function() { console.log("going ERR"); return this[2]; }
}
};
var machine = Stately.machine( stObj );
machine.onbefore0 = function(sS,eN,lSn,nSn) { console.log("onbefore: ",sS,eN,lSn,nSn); }
machine.onenter0 = function(sS,eN,lSn,nSn) { console.log("onenter: ",sS,eN,lSn,nSn); }
machine.onleave0 = function(sS,eN,lSn,nSn) { console.log("onleave: ",sS,eN,lSn,nSn); }
machine.onbefore1 = function(sS,eN,lSn,nSn) { console.log("onbefore: ",sS,eN,lSn,nSn); }
machine.onenter1 = function(sS,eN,lSn,nSn) { console.log("onenter: ",sS,eN,lSn,nSn); }
machine.onleave1 = function(sS,eN,lSn,nSn) { console.log("onleave: ",sS,eN,lSn,nSn); }
machine.onbefore2 = function(sS,eN,lSn,nSn) { console.log("onbefore: ",sS,eN,lSn,nSn); }
machine.onenter2 = function(sS,eN,lSn,nSn) { console.log("onenter: ",sS,eN,lSn,nSn); }
machine.onleave2 = function(sS,eN,lSn,nSn) { console.log("onleave: ",sS,eN,lSn,nSn); }
console.log("INITIAL STATE (first writed object property is '1'): BUT :",machine.getMachineState(),
"\n---------------------------------------------- \n\
I want default LOG1 ... ON \n\
For some reasons I cannot forget possibility of numerical object properties \n\
Simple .... THIS IS DEFINED(and I have no reason to forbid) BY USER, not me as programmer. \n\
( real time, user re-configurable application ... \n\
again USER RECONFIGURABLE ! ) and if somebody loves pure numbers .... ? let him live! \n\
" );
function rndState () {
return parseInt(Math.random()*3);
}
setInterval( function() {
console.log("BEFORE: ",machine.getMachineState());
var transition = rndState ();
console.log("RANDOM: ",transition);
machine[['on','off','err'][transition]]();
console.log("AFTER: ",machine.getMachineState());
}, 1000)

@supipd please take a look at the devel branch if it suit your needs. You can now pass in an additional argument with the name of the desired initial state: Stately(statesObject, initialStateName);
Thanks a lot, it's better.
(extreme: javascript allow use as property name empty string "" ... so problem is again in combination states
'2' ... error
'1': ... on
'0' ... off
'' ... unknown
var initStateName; ( initStateName == "") === ( initStateName =='0') ... true )
But this is really extreme. Thanks again.