-
Notifications
You must be signed in to change notification settings - Fork 2
/
henderson.min.js
1 lines (1 loc) · 1.1 KB
/
henderson.min.js
1
!function(n){function e(n,e){var t=Error.call(this,"Transition from "+n+" to "+e+" is not allowed");return t.name="IllegalTransitionException",t.prev=n,t.attempt=e,t}function t(n){function t(n){return r[n]||[]}var r={},o={transitions:n.states,current:n.initial,error:n.error};return o.bind=function(n,e){return r[n]=r[n]||[],r[n]=r[n].concat(e),o},o.unbind=function(n,e){return n in r&&r[n].indexOf(e)>-1&&r[n].splice(r[n].indexOf(e),1),o},o.on=o.bind,o.go=function(n){function r(e){return e<u.length?[n]:e<s.length?[i]:[i,n]}var i=o.current,c=Array.prototype.slice.call(arguments,1);if(o.transitions[i].indexOf(n)<0)return Promise.reject(new e(i,n));var u=t("after:"+i),f=t("before:"+n),a=t(n),l=t("*"),s=u.concat(f,a),d=u.length+f.length;return s.concat(l,function(){}).reduce(function(e,t,i){var u=r(i).concat(c);return e.then(function(){return i===d&&(o.current=n),t.apply(t,u)})},Promise.resolve())},o}"function"==typeof define&&"object"==typeof define.amd&&define.amd?define(function(){return t}):"object"==typeof module&&module.exports?module.exports=t:"undefined"!=typeof self?self.StateMachine=t:n.StateMachine=t}(this);