var fsm = new PromiseStateMachine({
initial: 'green',
events: {
warn: { from: 'green', to: 'yellow' },
panic: { from: 'yellow', to: 'red' },
calm: { from: 'red', to: 'yellow' },
clear: { from: 'yellow', to: 'green' }
}
});
fsm.on('warn', function(event, from, to, anyArgs) {
return Promise.resolve('result 1');
});
fsm.on('warn', function(event, from, to, anyArgs) {
var transaction = anyArgs[0];
var somethingElse = anyArgs[1];
return Promise.resolve('result 2');
});
fsm.warn(transaction, somethingElse).then(function(results) {
}).error(function(error) {
});
fsm.is('green');
fsm.is('yellow');
fsm.state();
fsm.can('calm');
fsm.can('panic');
var MyObject = function() {
PromiseStateMachine.call(this, {
initial: 'green',
events: {
warn: { from: 'green', to: 'yellow' },
panic: { from: 'yellow', to: 'red' },
calm: { from: 'red', to: 'yellow' },
clear: { from: 'yellow', to: 'green' }
}
});
};
_.extend(MyObject, PromiseStateMachine);
_.extend(MyObject.prototype, PromiseStateMachine.prototype);
var fsm = new MyObject();
fsm.is('green');
fsm.warn().then(function() {
fsm.is('green');
});