Skip to content

Commit ab54598

Browse files
committed
[docs] Add history states docs
Add startFrom overload with stateName argument.
1 parent 364a8c2 commit ab54598

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

docs/index.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,28 @@ choiceState {
412412
}
413413
```
414414

415+
### History states
416+
417+
There are two types of history states, shallow and deep. Shallow history state is used to represent the most recently
418+
active child (its neighbour) of a parent state. It does not recurse into this child's active configuration (sub states),
419+
initial states will be used. Deep history state in contrast reflects the most recent active configuration of the parent
420+
state (including all sub states).
421+
You can specify default state which will be used if history was not recorded yet (parent was not active).
422+
When default state is not specified, parent initial state will be entered on transition to history state.
423+
424+
```kotlin
425+
val machine = createStateMachine {
426+
state {
427+
val state11 = initialState()
428+
val state12 = state()
429+
historyState(defultState = state12)
430+
}
431+
state {
432+
// ...
433+
}
434+
}
435+
```
436+
415437
## Typesafe transitions
416438

417439
It is a common case when a state expects to receive some data from an event. Library provides typesafe API for such

kstatemachine/src/main/kotlin/ru/nsk/kstatemachine/Testing.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ object Testing {
66
*/
77
fun StateMachine.startFrom(state: IState, argument: Any? = null) =
88
(this as InternalStateMachine).startFrom(state, argument)
9+
10+
fun StateMachine.startFrom(stateName: String, argument: Any? = null) =
11+
startFrom(requireState(stateName), argument)
912
}

0 commit comments

Comments
 (0)