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

Multiple from/to in transition definition block #210

Open
marclennox opened this issue Apr 22, 2016 · 4 comments
Open

Multiple from/to in transition definition block #210

marclennox opened this issue Apr 22, 2016 · 4 comments

Comments

@marclennox
Copy link

Is there a way to specify an array of from: or to: states in the transition definition block? If not are you open to a PR?

@marclennox
Copy link
Author

I'm looking at the code and it seems that you do support an array for the to: state but not from: and it looks like an easy change in the callback.rb file to allow this.

@greysteil
Copy link
Contributor

I think this has been discussed before, and we decided that having array-to-array callbacks could be confusing. @hmarr - do you have the context?

@hmarr
Copy link
Contributor

hmarr commented Apr 23, 2016

Yes, there was a long discussion about this in #95.

This comment describes the original reasoning. We actually initially allowed arrays for both :from and :to, but found the resulting code pretty unclear.

@marclennox it's probably worth starting by having a skim through #95. After that, if you've got a good example of where supporting a :from array would be beneficial, we can revisit. Otherwise I'd rather stick with the current decision.

@marclennox
Copy link
Author

Thanks @hmarr. I recently moved away from the state_machine gem to statesman and statesman-events and was trying to keep the logic as close to the same as possible.

I use the events module and have a few cases where different events transition to the same 'to' state, but from different 'from' states. Depending on the event that triggered the transition, I may have different logic in after_transition when transitioning from one of the 'from' states, but for the others it's the same logic. For the 'others' that have the same logic, I now need to duplicate the code in multiple after_transition blocks.

Perhaps this is not a proper use of a state machine, but this is how I did it with state_machine which did support this use-case.

Alternatively, is there a way I can get access to the triggering event or the 'from' state from within the after_transition block?

I was able to make the code change to statesman quite easily, it was obvious that multiple from states had been previously supported.

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

No branches or pull requests

3 participants