有没有办法在 Machina.js 中的特定状态之间转换时执行操作?
例如,假设我有状态“A、B、C”。
我想写一个像这样的函数:
when("A", "C", function(){ console.log("Caught transition from A to C! Yay!"); }
这与 Akka's FSM 的精神相同。执行。这可能吗?
谢谢!
最佳答案
想通了。只需要注意 transition
事件即可。请参阅API doc here .
var fsm = new machina.Fsm({
initialState: 'A',
states: {
"A": {},
"B" : {},
"C" : {}
}
});
fsm.on('transition', function(transition){
console.log("[" + transition.fromState + "] -(" + transition.action + ")-> [" + transition.toState + "]");
});
关于javascript - 从一种特定状态转换到另一种特定状态时执行操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27130073/