Timeful States
Immutable states with timestamps.
Usage
var States = ; var transitions = // called when 'birth' state is triggered { toStatebirthday = fromStatetime; // birthday is the from states time/date toStateage = 0; } // called when switching from 'birth' to 'dead' state { toStateage = duration; // age is the duration between the state switches toStateobit = toStatetime; // time of death is the to states time/date }; // create new states container with given transitions and initial statevar states = ; // create state object with given unique keyvar firstState = states;var secondState = states; secondState; // a state is a function, when called returns the current state dataconsole; // ~0; ; // get state by keyconsole; // > 0 // set internal state valuefirstState;firstState; // get state namestate; // clear all stored statesstatesclear;
You can force to retrigger an already set state again:
state;state; // this will trigger the state transition for 'dead' again