Comments (2)
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?
from transitions.
Oh, I completely missed the possibility to use a 'next_state' trigger. For me it will do the job. Thanks!
from transitions.
Related Issues (20)
- AsyncMachine transitions fail when a list of `State` objects are passed in to the FSM. HOT 2
- get_triggers does not work HOT 3
- Cannot use Pydantic `BaseModel` class for models HOT 2
- All possible transitions are initialized, instead of those provided as an argument. HOT 2
- Machine get into wrong state. HOT 1
- after_state_change not triggered by set_state HOT 2
- AsyncMachine with queued transitions breaks when transition is cancelled
- AsyncMachine transitions aren't atomic
- The Event and Machine have cyclic dependency. HOT 3
- Update COPR packages
- get_triggers does not get child states in HierarchicalAsyncMachine HOT 1
- may_ function in parallel state does not report correct value
- 3.12 Performance HOT 9
- Call triggers by name HOT 2
- New version release HOT 5
- Very confusing in inherited HierarchicalMachine. HOT 1
- Pylance attributeerror on generated members HOT 6
- 😭 How do you specify final state? The front page docs do not say HOT 1
- Is it normal to have a bunch of warnings of "event doesn't exist" for parallel machines (with disjoint event sets)? HOT 1
- Provide features to ease static type checking HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from transitions.