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

Remove on_transition callback #44

Open
piotrmurach opened this issue Feb 22, 2016 · 5 comments
Open

Remove on_transition callback #44

piotrmurach opened this issue Feb 22, 2016 · 5 comments

Comments

@piotrmurach
Copy link
Owner

@craiglittle I feel as though we should drop the on_transition callback, I haven't used it myself and don't really see a reason any more for its existence?

@craiglittle
Copy link
Contributor

I use on_transition in our app, but I don't see any reason why on_enter can't work in its stead.

What was your reasoning for including on_transition in the first place?

In any case, if you want to remove it, it'd probably make sense at v2.0.0.

@piotrmurach
Copy link
Owner Author

The semantics of on_transition sounded good, and explained probably well the intention. However, looking at the trigger implementation, the on_transiton is equivalent to on_enter, hence thought I will just drop it. Keep the codebase to minimum. The finite_machine hasn't reached v1.0.0 yet :)

@craiglittle
Copy link
Contributor

Er, yeah, I meant v1.0.0 (or, I guess, v0.12.0). :)

@dmgr
Copy link

dmgr commented May 29, 2017

Actually I think on_transition callback is quite useful, but limited due to its lack of recognition of from and to states. It can be a lot more useful if it would let you specify from and to states like that:

on_transition :started => :stopped do |event| ...
on_transition any => :broken do |event| ... # `any` state as a singleton object (see below)
on_transition %i[stopped broken] => :started do |event| ...

Currently I use the if conditional to test from/to states:

on_transition do |event|
  if event.from == :started && event.to == :stopped ...

# or:

on_transition :stopped do |event|
  if event.from == :started ...

The other thing is that internally any state shouldn't be a symbol, but a unique singleton object, to never collide with any user defined states:

any = String.new('any').frozen
# or:
any = 'any'.frozen # it generates unique object, but it may change in the future Ruby releases
# or:
any = String('any').frozen

piotrmurach added a commit that referenced this issue Oct 30, 2018
@piotrmurach
Copy link
Owner Author

@dmgr I've released v0.12.0 which includes any_state to prevent any clashes with :any keys. Your idea about on_transition to allow from states is intriguing but I'm kind of worried that it will exponentially increase internal complexity for the storage of callbacks.

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

No branches or pull requests

3 participants