javascript-state-machine
Advanced tools
Comparing version 2.3.4 to 2.3.5
{ | ||
"name": "javascript-state-machine", | ||
"version": "2.3.4", | ||
"version": "2.3.5", | ||
"homepage": "https://github.com/jakesgordon/javascript-state-machine", | ||
@@ -5,0 +5,0 @@ "authors": [ |
@@ -12,3 +12,3 @@ { | ||
}, | ||
"version": "2.3.4" | ||
"version": "2.3.5" | ||
} |
@@ -1,2 +0,2 @@ | ||
Javascript Finite State Machine (v2.3.4) | ||
Javascript Finite State Machine (v2.3.5) | ||
======================================== | ||
@@ -3,0 +3,0 @@ |
@@ -0,1 +1,6 @@ | ||
Version 2.3.5 (January 20 2014) | ||
------------------------------- | ||
* fix for broken transitions() method (issue #74) | ||
Version 2.3.4 (January 17 2014) | ||
@@ -2,0 +7,0 @@ ------------------------------- |
@@ -16,3 +16,3 @@ /* | ||
VERSION: "2.3.4", | ||
VERSION: "2.3.5", | ||
@@ -53,4 +53,4 @@ //--------------------------------------------------------------------------- | ||
for (var n = 0 ; n < from.length ; n++) { | ||
transitions[e.from] = transitions[e.from] || []; | ||
transitions[e.from].push(e.name); | ||
transitions[from[n]] = transitions[from[n]] || []; | ||
transitions[from[n]].push(e.name); | ||
@@ -57,0 +57,0 @@ map[e.name][from[n]] = e.to || from[n]; // allow no-op transition if 'to' is not specified |
@@ -1,1 +0,1 @@ | ||
(function(){var a={VERSION:"2.3.4",Result:{SUCCEEDED:1,NOTRANSITION:2,CANCELLED:3,PENDING:4},Error:{INVALID_TRANSITION:100,PENDING_TRANSITION:200,INVALID_CALLBACK:300},WILDCARD:"*",ASYNC:"async",create:function(g,h){var j=(typeof g.initial=="string")?{state:g.initial}:g.initial;var f=g.terminal||g["final"];var e=h||g.target||{};var m=g.events||[];var i=g.callbacks||{};var c={};var k={};var l=function(o){var q=(o.from instanceof Array)?o.from:(o.from?[o.from]:[a.WILDCARD]);c[o.name]=c[o.name]||{};for(var p=0;p<q.length;p++){k[o.from]=k[o.from]||[];k[o.from].push(o.name);c[o.name][q[p]]=o.to||q[p]}};if(j){j.event=j.event||"startup";l({name:j.event,from:"none",to:j.state})}for(var d=0;d<m.length;d++){l(m[d])}for(var b in c){if(c.hasOwnProperty(b)){e[b]=a.buildEvent(b,c[b])}}for(var b in i){if(i.hasOwnProperty(b)){e[b]=i[b]}}e.current="none";e.is=function(n){return(n instanceof Array)?(n.indexOf(this.current)>=0):(this.current===n)};e.can=function(n){return !this.transition&&(c[n].hasOwnProperty(this.current)||c[n].hasOwnProperty(a.WILDCARD))};e.cannot=function(n){return !this.can(n)};e.transitions=function(){return k[this.current]};e.isFinished=function(){return this.is(f)};e.error=g.error||function(p,t,s,o,n,r,q){throw q||r};if(j&&!j.defer){e[j.event]()}return e},doCallback:function(g,d,c,i,h,b){if(d){try{return d.apply(g,[c,i,h].concat(b))}catch(f){return g.error(c,i,h,b,a.Error.INVALID_CALLBACK,"an exception occurred in a caller-provided callback function",f)}}},beforeAnyEvent:function(d,c,f,e,b){return a.doCallback(d,d.onbeforeevent,c,f,e,b)},afterAnyEvent:function(d,c,f,e,b){return a.doCallback(d,d.onafterevent||d.onevent,c,f,e,b)},leaveAnyState:function(d,c,f,e,b){return a.doCallback(d,d.onleavestate,c,f,e,b)},enterAnyState:function(d,c,f,e,b){return a.doCallback(d,d.onenterstate||d.onstate,c,f,e,b)},changeState:function(d,c,f,e,b){return a.doCallback(d,d.onchangestate,c,f,e,b)},beforeThisEvent:function(d,c,f,e,b){return a.doCallback(d,d["onbefore"+c],c,f,e,b)},afterThisEvent:function(d,c,f,e,b){return a.doCallback(d,d["onafter"+c]||d["on"+c],c,f,e,b)},leaveThisState:function(d,c,f,e,b){return a.doCallback(d,d["onleave"+f],c,f,e,b)},enterThisState:function(d,c,f,e,b){return a.doCallback(d,d["onenter"+e]||d["on"+e],c,f,e,b)},beforeEvent:function(d,c,f,e,b){if((false===a.beforeThisEvent(d,c,f,e,b))||(false===a.beforeAnyEvent(d,c,f,e,b))){return false}},afterEvent:function(d,c,f,e,b){a.afterThisEvent(d,c,f,e,b);a.afterAnyEvent(d,c,f,e,b)},leaveState:function(f,e,h,g,d){var c=a.leaveThisState(f,e,h,g,d),b=a.leaveAnyState(f,e,h,g,d);if((false===c)||(false===b)){return false}else{if((a.ASYNC===c)||(a.ASYNC===b)){return a.ASYNC}}},enterState:function(d,c,f,e,b){a.enterThisState(d,c,f,e,b);a.enterAnyState(d,c,f,e,b)},buildEvent:function(b,c){return function(){var h=this.current;var g=c[h]||c[a.WILDCARD]||h;var e=Array.prototype.slice.call(arguments);if(this.transition){return this.error(b,h,g,e,a.Error.PENDING_TRANSITION,"event "+b+" inappropriate because previous transition did not complete")}if(this.cannot(b)){return this.error(b,h,g,e,a.Error.INVALID_TRANSITION,"event "+b+" inappropriate in current state "+this.current)}if(false===a.beforeEvent(this,b,h,g,e)){return a.Result.CANCELLED}if(h===g){a.afterEvent(this,b,h,g,e);return a.Result.NOTRANSITION}var f=this;this.transition=function(){f.transition=null;f.current=g;a.enterState(f,b,h,g,e);a.changeState(f,b,h,g,e);a.afterEvent(f,b,h,g,e);return a.Result.SUCCEEDED};this.transition.cancel=function(){f.transition=null;a.afterEvent(f,b,h,g,e)};var d=a.leaveState(this,b,h,g,e);if(false===d){this.transition=null;return a.Result.CANCELLED}else{if(a.ASYNC===d){return a.Result.PENDING}else{if(this.transition){return this.transition()}}}}}};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports){exports=module.exports=a}exports.StateMachine=a}else{if(typeof define==="function"&&define.amd){define(function(b){return a})}else{if(typeof window!=="undefined"){window.StateMachine=a}else{if(typeof self!=="undefined"){self.StateMachine=a}}}}}()); | ||
(function(){var a={VERSION:"2.3.5",Result:{SUCCEEDED:1,NOTRANSITION:2,CANCELLED:3,PENDING:4},Error:{INVALID_TRANSITION:100,PENDING_TRANSITION:200,INVALID_CALLBACK:300},WILDCARD:"*",ASYNC:"async",create:function(g,h){var j=(typeof g.initial=="string")?{state:g.initial}:g.initial;var f=g.terminal||g["final"];var e=h||g.target||{};var m=g.events||[];var i=g.callbacks||{};var c={};var k={};var l=function(o){var q=(o.from instanceof Array)?o.from:(o.from?[o.from]:[a.WILDCARD]);c[o.name]=c[o.name]||{};for(var p=0;p<q.length;p++){k[q[p]]=k[q[p]]||[];k[q[p]].push(o.name);c[o.name][q[p]]=o.to||q[p]}};if(j){j.event=j.event||"startup";l({name:j.event,from:"none",to:j.state})}for(var d=0;d<m.length;d++){l(m[d])}for(var b in c){if(c.hasOwnProperty(b)){e[b]=a.buildEvent(b,c[b])}}for(var b in i){if(i.hasOwnProperty(b)){e[b]=i[b]}}e.current="none";e.is=function(n){return(n instanceof Array)?(n.indexOf(this.current)>=0):(this.current===n)};e.can=function(n){return !this.transition&&(c[n].hasOwnProperty(this.current)||c[n].hasOwnProperty(a.WILDCARD))};e.cannot=function(n){return !this.can(n)};e.transitions=function(){return k[this.current]};e.isFinished=function(){return this.is(f)};e.error=g.error||function(p,t,s,o,n,r,q){throw q||r};if(j&&!j.defer){e[j.event]()}return e},doCallback:function(g,d,c,i,h,b){if(d){try{return d.apply(g,[c,i,h].concat(b))}catch(f){return g.error(c,i,h,b,a.Error.INVALID_CALLBACK,"an exception occurred in a caller-provided callback function",f)}}},beforeAnyEvent:function(d,c,f,e,b){return a.doCallback(d,d.onbeforeevent,c,f,e,b)},afterAnyEvent:function(d,c,f,e,b){return a.doCallback(d,d.onafterevent||d.onevent,c,f,e,b)},leaveAnyState:function(d,c,f,e,b){return a.doCallback(d,d.onleavestate,c,f,e,b)},enterAnyState:function(d,c,f,e,b){return a.doCallback(d,d.onenterstate||d.onstate,c,f,e,b)},changeState:function(d,c,f,e,b){return a.doCallback(d,d.onchangestate,c,f,e,b)},beforeThisEvent:function(d,c,f,e,b){return a.doCallback(d,d["onbefore"+c],c,f,e,b)},afterThisEvent:function(d,c,f,e,b){return a.doCallback(d,d["onafter"+c]||d["on"+c],c,f,e,b)},leaveThisState:function(d,c,f,e,b){return a.doCallback(d,d["onleave"+f],c,f,e,b)},enterThisState:function(d,c,f,e,b){return a.doCallback(d,d["onenter"+e]||d["on"+e],c,f,e,b)},beforeEvent:function(d,c,f,e,b){if((false===a.beforeThisEvent(d,c,f,e,b))||(false===a.beforeAnyEvent(d,c,f,e,b))){return false}},afterEvent:function(d,c,f,e,b){a.afterThisEvent(d,c,f,e,b);a.afterAnyEvent(d,c,f,e,b)},leaveState:function(f,e,h,g,d){var c=a.leaveThisState(f,e,h,g,d),b=a.leaveAnyState(f,e,h,g,d);if((false===c)||(false===b)){return false}else{if((a.ASYNC===c)||(a.ASYNC===b)){return a.ASYNC}}},enterState:function(d,c,f,e,b){a.enterThisState(d,c,f,e,b);a.enterAnyState(d,c,f,e,b)},buildEvent:function(b,c){return function(){var h=this.current;var g=c[h]||c[a.WILDCARD]||h;var e=Array.prototype.slice.call(arguments);if(this.transition){return this.error(b,h,g,e,a.Error.PENDING_TRANSITION,"event "+b+" inappropriate because previous transition did not complete")}if(this.cannot(b)){return this.error(b,h,g,e,a.Error.INVALID_TRANSITION,"event "+b+" inappropriate in current state "+this.current)}if(false===a.beforeEvent(this,b,h,g,e)){return a.Result.CANCELLED}if(h===g){a.afterEvent(this,b,h,g,e);return a.Result.NOTRANSITION}var f=this;this.transition=function(){f.transition=null;f.current=g;a.enterState(f,b,h,g,e);a.changeState(f,b,h,g,e);a.afterEvent(f,b,h,g,e);return a.Result.SUCCEEDED};this.transition.cancel=function(){f.transition=null;a.afterEvent(f,b,h,g,e)};var d=a.leaveState(this,b,h,g,e);if(false===d){this.transition=null;return a.Result.CANCELLED}else{if(a.ASYNC===d){return a.Result.PENDING}else{if(this.transition){return this.transition()}}}}}};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports){exports=module.exports=a}exports.StateMachine=a}else{if(typeof define==="function"&&define.amd){define(function(b){return a})}else{if(typeof window!=="undefined"){window.StateMachine=a}else{if(typeof self!=="undefined"){self.StateMachine=a}}}}}()); |
@@ -147,2 +147,36 @@ //----------------------------------------------------------------------------- | ||
test("transitions with multiple from states", function() { | ||
var fsm = StateMachine.create({ | ||
events: [ | ||
{ name: 'start', from: 'none', to: 'green' }, | ||
{ name: 'warn', from: ['green', 'red'], to: 'yellow' }, | ||
{ name: 'panic', from: ['green', 'yellow'], to: 'red' }, | ||
{ name: 'clear', from: ['red', 'yellow'], to: 'green' } | ||
] | ||
}); | ||
equal(fsm.current, 'none', 'current state should be none'); | ||
deepEqual(fsm.transitions(), ['start'], 'current transition(s) should be start'); | ||
fsm.start(); | ||
equal(fsm.current, 'green', 'current state should be green'); | ||
deepEqual(fsm.transitions(), ['warn', 'panic'], 'current transition(s) should be warn and panic'); | ||
fsm.warn(); | ||
equal(fsm.current, 'yellow', 'current state should be yellow'); | ||
deepEqual(fsm.transitions(), ['panic', 'clear'], 'current transition(s) should be panic and clear'); | ||
fsm.panic(); | ||
equal(fsm.current, 'red', 'current state should be red'); | ||
deepEqual(fsm.transitions(), ['warn', 'clear'], 'current transition(s) should be warn and clear'); | ||
fsm.clear(); | ||
equal(fsm.current, 'green', 'current state should be green'); | ||
deepEqual(fsm.transitions(), ['warn', 'panic'], 'current transition(s) should be warn and panic'); | ||
}); | ||
//----------------------------------------------------------------------------- | ||
test("isFinished", function() { | ||
@@ -149,0 +183,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1093704
3789