我有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
如何在事件1中仅在第一次转换的回调后设置? (我无法替换其他事件的第二次过渡)
我试过
event :event1 do
transitions to: :state2, from: :state1, after: :event2!, guard: proc {some func}
transitions to: :state3, from: :state1
end
但它不起作用
答案 0 :(得分:0)
我不确定我是否准确到达。您只想在此转换后运行 var segResp = new SearchResponse<SegmentRecord>();
elasticClientMock.Setup(ec => ec.Search(
It.IsAny<Func<SearchDescriptor<SegmentRecord>,
SearchDescriptor<SegmentRecord>>>()))
.Returns(segResp);
: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
这段代码意味着,当guard返回true时,它将执行第一次转换,否则它将执行第二次转换。转换后,如果它是state2,它将执行event2.您可以在aasm找到更多详细信息。
如果事件有多个转换,则第一个转换 成功完成的转换将停止其他转换 来自同一事件的处理。
您可以在回调中编写任何代码,就像rails回调一样。