-
Notifications
You must be signed in to change notification settings - Fork 523
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
conditions in ordered_transitions #19
Comments
Hmm... that's an interesting idea, but I'm not sure it's a common enough use case to warrant adding. I think there are two alternative approaches that might work better. One is to just fall back on the standard approach and add all transitions explicitly rather than using the ordered_transitions shorthand. I.e., instead of machine.add_ordered_transitions(['A', 'C', 'B'], trigger='next_state') ...one can always write: transitions = [['next_state', 'A', 'C', 'this_must_pass'], ['next_state', 'C', 'B']] ...which will usually not be very verbose. I think for the few cases where an individual condition is needed for an ordered chain, and there aren't very many states, that's probably a reasonable approach. When there are a lot of states, adding all the transitions explicitly might become a pain. In that case I think a reasonable way to handle this would be to add some kind of update_transition or replace_transition method--or maybe add a boolean 'replace' argument to Machine.add_transition() that overwrites any existing matching transition instead of always appending. Then your problem could be solved by doing one of the following: # Create the chain
machine.add_ordered_transitions(['A', 'C', 'B'], trigger='next_state')
# Option A: get transition and manually update state
t = machine.get_transition('next_state', 'A', 'C')
t.add_condition('this_must_pass')
# Option B: replace transition in place
machine.add_transition('next_state', 'A', 'C', conditions='this_must_pass', replace=True) I'm okay with either approach, but I think the first one might be a better way to go as it would probably be generally useful to let users easily retrieve existing transitions for inspection/modification. Thoughts? |
Oh, I completely missed the possibility to use a 'next_state' trigger. For me it will do the job. Thanks! |
Hi, it's me again 馃槃
As far as I understand there is no way at the moment to specify a condition for a single transition in a chain? If you don't mind about the feature I could provide a pull request for the feature.
The text was updated successfully, but these errors were encountered: