Skip to content

Commit

Permalink
[docs] Add history states docs
Browse files Browse the repository at this point in the history
Add startFrom overload with stateName argument.
  • Loading branch information
nsk90 committed Sep 4, 2022
1 parent 364a8c2 commit ab54598
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,28 @@ choiceState {
}
```

### History states

There are two types of history states, shallow and deep. Shallow history state is used to represent the most recently
active child (its neighbour) of a parent state. It does not recurse into this child's active configuration (sub states),
initial states will be used. Deep history state in contrast reflects the most recent active configuration of the parent
state (including all sub states).
You can specify default state which will be used if history was not recorded yet (parent was not active).
When default state is not specified, parent initial state will be entered on transition to history state.

```kotlin
val machine = createStateMachine {
state {
val state11 = initialState()
val state12 = state()
historyState(defultState = state12)
}
state {
// ...
}
}
```

## Typesafe transitions

It is a common case when a state expects to receive some data from an event. Library provides typesafe API for such
Expand Down
3 changes: 3 additions & 0 deletions kstatemachine/src/main/kotlin/ru/nsk/kstatemachine/Testing.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ object Testing {
*/
fun StateMachine.startFrom(state: IState, argument: Any? = null) =
(this as InternalStateMachine).startFrom(state, argument)

fun StateMachine.startFrom(stateName: String, argument: Any? = null) =
startFrom(requireState(stateName), argument)
}

0 comments on commit ab54598

Please sign in to comment.