fsm2
FMS2 提供了 UML 狀態圖核心設計方面的 Dart 實現。
- 星標
- 53
- 分支
- 6
- 最近推送(UTC)
- 2026年8月16日
- 專案狀態
- 未封存
原始 README
以下為英文專案原文快照,最新內容請造訪 GitHub。
FSM2 provides an implementation of the core design aspects of the UML2 state diagrams.
FMS2 supports:
- Nested States
- Concurrent Regions
- Guard Conditions
- sideEffects
- onEnter/onExit
- streams
- static analysis tools
- visualisation tools.
Overview
FSM2 uses a builder to delcare each state machine.
Your application may declare as many statemachines as necessary.
Example
import 'package:fsm2/fsm2.dart';
void main() {
final machine = StateMachine.create((g) => g
..initialState(Solid())
..state<Solid>((b) => b
..on<OnMelted, Liquid>(sideEffect: (e) async => print("I'm melting"))
..state<Liquid>((b) {})
));
The above examples creates a Finite State Machine (machine) which declares its initial state as being Solid and then declares a single
transition which occurs when the event OnMelted event is triggered causing a transition to a new state Liquid.
To trigger an event:
machine.applyEvent(OnMelted());
Documentation
Full documentation is available on gitbooks at:
https://fsm2.onepub.dev/
Example 2
A simple example showing the life cycle of H2O.
import 'package:fsm2/fsm2.dart';
void main() {
final machine = StateMachine.create((g) => g
..initialState(Solid())
..state<Solid>((b) => b
..on<OnMelted, Liquid>(sideEffect: (e) => print('Melted'),
)))
..state<Liquid>((b) => b
..onEnter((s, e) => print('Entering ${s.runtimeType} State'))
..onExit((s, e) => print('Exiting ${s.runtimeType} State'))
..on<OnFroze, Solid>(sideEffect: (e) => print('Frozen')))
..on<OnVaporized, Gas>(sideEffect: (e) => print('Vaporized'))))
..state<Gas>((b) => b
..on<OnCondensed, Liquid>(sideEffect: (e) => print('Condensed'))))
..onTransition((t) => print(
'Received Event ${t.event.runtimeType} in State ${t.fromState.runtimeType} transitioning to State ${t.toState.runtimeType}')));
await machine.complete;
/// machine.isInState<Hard>()
print(machine.isInSt<Solid>); // TRUE
machine.transition(OnMelted());
print(machine.isInState<Liquid>); // TRUE
machine.transition(OnFroze());
print(machine.isInState<Solid>); // TRUE
}
Credits:
FMS2 is derived from the FSM library which in turn was inspired by Tinder StateMachine library.
分類
使用的依賴
如何選擇適合專案的儲存庫?
先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。
- 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
- 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
- 使用前在 GitHub 確認 README、授權條款與 Issues。
來源與維護
“A repository is the most basic element of GitHub.”
GitHub Docs — About repositories ↗