workiva / state_machine Goto Github PK
View Code? Open in Web Editor NEWEasily create a finite state machine and define legal state transitions. Listen to state entrances, departures, and transitions.
License: Other
Easily create a finite state machine and define legal state transitions. Listen to state entrances, departures, and transitions.
License: Other
The current Dart SDK version is 2.1.0-dev.1.0.flutter-ccb16f7282.
Because {appName} depends on state_machine >=2.0.0 which requires SDK version >=1.9.0 <2.0.0, version solving failed.
pub get failed (1)
From #61 (comment)
Since this is a fairly low-level package, it would be nice to remove any dependencies that aren't strictly necessary. Disposable is one of those, since Machine
could provide that functionality via a dispose()
method that is easily integrated into an API like Disposable
if desired by the consumer.
that
If you have to guard against doing illegal transitions, you'll need another finite-state machine implementation (e.g. a switch) to do this. The current FSM implementation creates the very problem FSMs are meant to solve.
Doing the transitions directly is also, let's say, unorthodox.
Usually, you just throw events at the FSM and it transitions in response if it feels like it. E.g. in a platform game, if the player's character is already in the jumping state, pressing the jump button once more won't do anything (unless there is a doubleJumping state the FSM could transition to).
https://en.wikipedia.org/wiki/Finite-state_machine
[An FSM is] an abstract machine that can be in one of a finite number of states. The machine is in only one state at a time; the state it is in at any given time is called the current state. It can change from one state to another when initiated by a triggering event or condition; this is called a transition. A particular FSM is defined by a list of its states, and the triggering condition for each transition.
Also check what Robert Nystrom (the author of pub
and dartfmt
) wrote about this topic in his spare time:
Hi, trying to use your state package in a dart test project.
Code is below, but first here is the output with added comments as to where things are not as expected.
It's a traffic light in the UK, red, redamber, green, amber, red
Any suggestions as to what I am doing wrong would be grateful.
Entered: red
Exit: red
Entered: redamber
Exit: redamber
Entered: green. // okay so far
Entered: amber // but then enters amber before leaving green
Exit: green
Entered: red. // then enters red before leaving amber
Exit: amber
Code
import 'package:state_machine/state_machine.dart';
init() {
StateMachine trafficlight = StateMachine('trafficlight');
//states
State red = trafficlight.newState('red');
State redamber = trafficlight.newState('redamber');
State amber = trafficlight.newState('amber');
State green = trafficlight.newState('green');
//transitions
StateTransition readyToGo = trafficlight.newStateTransition('readyToGo', [red], redamber);
StateTransition go = trafficlight.newStateTransition('go', [redamber], green);
StateTransition readyToStop = trafficlight.newStateTransition('readyToStop', [green], amber);
StateTransition stop = trafficlight.newStateTransition('stop', [amber], red);
red.onEnter.listen((StateChange change) {
print('Entered: red');
readyToGo();
});
red.onLeave.listen((StateChange change) {
print('Exit: red');
});
redamber.onEnter.listen((StateChange change) {
print('Entered: redamber');
go();
});
redamber.onLeave.listen((StateChange change) {
print('Exit: redamber');
});
green.onEnter.listen((StateChange change) {
print('Entered: green');
readyToStop();
});
green.onLeave.listen((StateChange change) {
print('Exit: green');
});
amber.onEnter.listen((StateChange change) {
print('Entered: amber');
stop();
});
amber.onLeave.listen((StateChange change) {
print('Exit: amber');
});
// RUN
trafficlight.start(red);
}
I also tried this format, but onDone is never called
red.onEnter.listen(
(StateChange change) {
print('Entered: red');
},
onDone: () {
readyToGo();
}
);
State could have a .listen() method that shortcuts state.onEnter.listen()
. Similar to javascript-state-machine's shortcut callbacks: https://github.com/jakesgordon/javascript-state-machine#callbacks
I was going to suggest doing it in the call() so that state()
would be a shortcut for listen, but then you loose the boolean check... which could be moved elsewhere but I think it is cleanest there.
Hey, I just wondered why you chose to create a new package when there already is the statemachine
package.
I want to start adding a state machine to my code and am wondering which one to use. Thanks
The first example on the package page (https://pub.dartlang.org/packages/state_machine) does not compile
StateMachine light = new StateMachine();
Could you please update the package for flutter 2.0?
Definition of Parallel
https://www.w3.org/TR/scxml/#parallel
Is there any plan to support this feature?
thanks for reply.
A state machine should have the ability to listen to an Error Stream.
For example, perhaps you want to do some cleanup anytime there is an IllegalStateTransition.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.