-
-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
separate state and event callbacks #11
Comments
Agree, the My rational was simply to provide uniform interface and let the code sweat out what the user means, whether |
This is implemented in the master as agreed, I've also updated docs |
Nice. So now I have the following: callbacks {
on_exit_state { |event| puts "exit_#{event.from}" }
on_before_event { |event| puts "\tbefore_#{event.name}" }
on_transition_state { |event| puts "\t\ttransition: #{event.name}: #{event.from} -> #{event.to}" }
on_enter_state { |event| puts "\tenter_#{event.to}" }
on_after_event { |event| puts "after_#{event.name}" }
} Since events and states are now independent (from callback perspective), I guess you could drop the trailing callbacks {
on_exit { |event| puts "exit_#{event.from}" }
on_before { |event| puts "\tbefore_#{event.name}" }
on_transition { |event| puts "\t\ttransition: #{event.name}: #{event.from} -> #{event.to}" }
on_enter { |event| puts "\tenter_#{event.to}" }
on_after { |event| puts "after_#{event.name}" }
} Mind you if I try that, I get the following
|
Very good point - working on it. I've added some validations yesterday to throw |
Seems your callback error checking is a bit too strict now. Because state and event namespace is now separate, you should be able to have a state and an event with the same name. The following state machine is perfectly reasonable and works when the callbacks are removed. require 'finite_machine'
phone = FiniteMachine.define do
initial :on_hook
events {
event :off_hook, :on_hook => :off_hook
event :on_hook, :off_hook => :on_hook
}
callbacks {
on_before(:on_hook) { puts "receive on_hook event" }
on_enter(:on_hook) { puts "entering on_hook state" }
}
end
phone.off_hook
phone.on_hook Event names and state names should be allowed to be the same I think. |
Fixed on master! |
Thanks. |
In my opinion the
on_enter
andon_exit
callbacks for events are confusing.States and events are different concepts. By allowing
on_enter
andon_exit
on events a single namespace is created for states and events leading to ambiguous code. I.e. when you have an event:digit
and a state:digit
what does the callbackon_enter_digit
mean?I propose to have separate
before
andafter
callbacks for events:What was your rationale for merging callbacks for states and events?
The text was updated successfully, but these errors were encountered: