3

我有 2 个事件:

event :event1, after: :event2! do
  transitions to: :state2, from: :state1, guard: proc {some func}
  transitions to: :state3, from: :state1
end    

event :event2 do
  transitions to: :state3, from: state2, guard: proc {some func}
end

如何在回调后仅在 event1 中设置第一次转换?(我不能将第二次转换替换为其他事件)

我试过了

event :event1 do
  transitions to: :state2, from: :state1, after: :event2!, guard: proc {some func}
  transitions to: :state3, from: :state1
end 

但它不起作用

4

1 回答 1

0

我不确定我是否得到了你。你只想event2在这个过渡之后运行:transitions to: :state2, from: :state1, guard: proc {some func},对吗?

event :event1 do
  transitions to: :state2, from: :state1, :after => Proc.new {|*args| set_process(*args) } , guard: proc {some func}
  transitions to: :state3, from: :state1
end 

def set_process(name)
  event2!
end

或者试试这个。

event :event1 do
  transitions to: :state2, from: :state1, guard: proc {some func}
  transitions to: :state3, from: :state1
  after do
    event2! if self.state2?
  end
end    

event :event2 do
  transitions to: :state3, from: state2, guard: proc {some func}
end

这段代码的意思是,当guard返回true时,它会做第一个转换,否则它会做第二个。转换后,如果是state2,它会做event2。你可以在aasm找到更多细节。

如果一个事件有多个转换,成功完成的第一个转换将停止处理同一事件中的其他转换。

您可以在回调中编写任何代码,就像 rails 回调一样。

于 2015-08-18T14:10:20.073 回答