Automatic transitions from one state to another
raghav135 opened this issue · comments
R. Srinivasa Raghavan commented
I wanted to understand if any existing feature is present or planned for something like below?
var fsm = new StateMachine({
init: 'solid',
transitions: [
{ name: 'melt', from: 'solid', to: 'liquid' },
{ name: 'freeze', from: 'liquid', to: 'solid' },
{ name: 'vaporize', from: 'liquid', to: 'gas' },
{ name: 'condense', from: 'gas', to: 'liquid' }
],
methods: {
canMelt: function() { return this.inputTemperature > this.data.meltingPoint; },
canFreeze: function() { return this.inputTemperature <= this.data.meltingPoint; },
canVaporize: function() { return this.inputTemperature >= this.data.boilingPoint; },
canCondense: function() { return this.inputTemperature < this.data.boilingPoint;}
},
data: { name: 'water', boilingPoint : 100, meltingPoint: 0 },
inputTemperature: 135
});
After this, lets say a new method "pushWorkflow" on the StateMachine
fsm.pushWorkflow();
console.log(fsm.state);
Should display : gas
Kindly let me know if it is not there and will you be happy to accept a pull request in similar lines?
Please suggest some changes if you feel something is not right.