You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+35-8Lines changed: 35 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -45,6 +45,7 @@
45
45
*[Migration guide from versions older than v0.20.0](#migration-guide-from-versions-older-than-v0200)
46
46
*[Export](#export)
47
47
*[PlantUML](#plantuml)
48
+
*[Mermaid](#mermaid)
48
49
*[Testing](#testing)
49
50
*[Multiplatform](#multiplatform)
50
51
*[Consider using Kotlin sealed classes](#consider-using-kotlin-sealed-classes)
@@ -433,7 +434,7 @@ createStateMachine(scope) {
433
434
Some of state machines and states are infinite, but other ones may finish.
434
435
435
436
* In `ChildMode.EXCLUSIVE` state or state machine finishes when enters top-level final state.
436
-
* In `ChildMode.PARALLEL` state or state machine finishes when all its children has finished.
437
+
* In `ChildMode.PARALLEL` state or state machine finishes when all its direct children has finished.
437
438
438
439
To make a state final, it must implement `FinalState` marker interface.
439
440
Built-in implementation of such state is `DefaultFinalState`.
@@ -447,6 +448,8 @@ sealed class States : DefaultState() {
447
448
}
448
449
```
449
450
451
+
See [Finished state sample](https://github.com/nsk90/kstatemachine/tree/master/samples/src/commonMain/kotlin/ru/nsk/samples/FinishedStateSample.kt)
452
+
450
453
Finishing of states and state machines is treated little differently.
451
454
State machine that was finished stops processing incoming events.
452
455
But when some nested state is finished its transitions are still active,
@@ -596,12 +599,12 @@ choiceState {
596
599
}
597
600
```
598
601
599
-
Thereis also `choiceDataState()` function available for choosing between `DataState`s. You can define `dataTransition`
602
+
Thereis also `choiceDataState()` function available for choosing between `DataState`s. You can define `dataTransition`
600
603
to target such pseudo data state.
601
604
602
605
You can use `choiceState` even on initial state branch.
603
-
Note that `choiceState` can not be active, so if the library performs a transition and finds that `choiceState` is
604
-
going to be activated, it executes its lambda argument and navigates to the resulting state.
606
+
Note that `choiceState` can not be active, so if the library performs a transition and finds that `choiceState` is
607
+
going to be activated, it executes its lambda argument and navigates to the resulting state.
605
608
If the resulting state is also a `PseudoState` instance, further redirections might be applied.
606
609
607
610
### History state
@@ -652,7 +655,7 @@ createStateMachine(scope) {
652
655
is activated it requires data value from a `DataEvent`. You can use `lastData` field to access last data value even
653
656
after state exit, it falls back to `defaultData` if provided or throws.
654
657
655
-
### Target-less data transitions
658
+
### Target-less data transitions
656
659
657
660
You can define target-less transitions for `DataState`. Please, note that if you want such transition to change state's
658
661
`data` field, it should be `EXTERNAL` type. If target-less transition is `LOCAL` it does not change states data.
@@ -871,9 +874,14 @@ Contains additional functions to work with KStateMachine depending on Kotlin Cor
871
874
## Export
872
875
873
876
> [!NOTE]
874
-
> Currently transitions that use lambdas like `transitionConditionally()` and`transitionOn()` are not exported.
875
-
> User defined lambdas that are passed to calculate next state could not be correctly
876
-
> called during export process as they may touch application data that is not valid when export is running.
877
+
> Transitions that use lambdas like `transitionConditionally()` and`transitionOn()` are not exported by default.
878
+
> You can enable their export with `unsafeCallConditionalLambdas` flag of `exportToPlantUml()` function.
879
+
> With `unsafeCallConditionalLambdas` flag set, user defined lambdas that are passed to the library to calculate next
880
+
> state would be called during export process. This will give more complete (still not full) export output,
881
+
> but may cause runtime errors depending on what the lambda actually do. As it may touch application data that is not
882
+
> valid when export is running, also `event` argument will be faked by unsafe cast, so touching it
883
+
> will cause `ClassCastException`
884
+
> That is why `unsafeCallConditionalLambdas` flag should be considered as debug/development tool only.
See [PlantUML nested states export sample](https://github.com/nsk90/kstatemachine/tree/master/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportSample.kt)
891
899
900
+
### Mermaid
901
+
902
+
`Mermaid` uses almost the same text format as `PlantUML`.
903
+
904
+
Use `exportToMermaid()`/`exportToToMermaidBlocking()` extension function to export state machine
905
+
to [Mermaid state diagram](https://mermaid.js.org/syntax/stateDiagram.html).
906
+
907
+
```kotlin
908
+
val machine = createStateMachine(scope) { /* ... */ }
909
+
println(machine.exportToPlantUml())
910
+
```
911
+
912
+
`Intellij IDEA` users may use official [Mermaid plugin](https://plugins.jetbrains.com/plugin/20146-mermaid)
913
+
to view diagrams directly in IDE for file types: `.mmd` and `.mermaid`.
914
+
915
+
Copy/paste resulting output to [Mermaid live editor](https://mermaid.live/)
916
+
917
+
See [Mermaid nested states export sample](https://github.com/nsk90/kstatemachine/tree/master/samples/src/commonMain/kotlin/ru/nsk/samples/MermaidExportSample.kt)
918
+
892
919
## Testing
893
920
894
921
For testing, it might be useful to check how state machine reacts on events from particular state. There
0 commit comments