Skip to content
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

Transition to initial state should trigger callbacks. #16

Closed
kjwierenga opened this issue May 26, 2014 · 3 comments
Closed

Transition to initial state should trigger callbacks. #16

kjwierenga opened this issue May 26, 2014 · 3 comments
Labels

Comments

@kjwierenga
Copy link

Is the initial pseudo state implicit? I think it would be wise to have a way to initiate the transition into the first state with an explicit call to initial!.

require 'finite_machine'

phone = FiniteMachine.define do
  initial :first

  callbacks {
    on_before { |event| puts "event #{event.name}" }
    on_enter(:first) { |event| puts "transition #{event.name} #{event.from} -> #{event.to}" }
  }
end

phone.start!

This would produce output:

event start!
transition INITIAL -> first

This initial transition could also be done as the last step in define but by having an explicit start! call the user has some control over when the initial transition is triggered.

Does this make sense?

@piotrmurach
Copy link
Owner

This should already work, the initial docs describes your case I think. Basically if you pass defer: true to initial, this will allow you to call the init event later on. Also by setting the event as deffered the very start state will be set to :none and thus transition :none => :first. Is that what you have in mind?

@kjwierenga
Copy link
Author

Ah, I forgot that. You’re absolutely right. But, if you don’t specify defer: true, then the initial transition doesn’t trigger callbacks. A small inconsistency?

Op 26 mei 2014, om 22:51 heeft Piotr Murach notifications@github.com het volgende geschreven:

This should already work, the initial docs describes your case I think. Basically if you pass defer: true to initial, this will allow you to call the init event later on. Also by setting the event as deffered the very start state will be set to :none and thus transition :none => :first. Is that what you have in mind?


Reply to this email directly or view it on GitHub.

@kjwierenga
Copy link
Author

Nice work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants