Skip to content

Commit

Permalink
Merge branch 'master' of github.com:psh/kotlin-state-machine
Browse files Browse the repository at this point in the history
  • Loading branch information
psh committed Sep 22, 2020
2 parents b6e36db + 4cd424a commit a928124
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[![Build Status](https://travis-ci.com/psh/kotlin-state-machine.svg?token=1nouCzPFZQuPA3QYtpm8&branch=master)](https://travis-ci.com/psh/kotlin-state-machine)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
[![ktlint](https://img.shields.io/badge/code%20style-%E2%9D%A4-FF4081.svg)](https://ktlint.github.io/)

# kotlin-state-machine

## Example State Machine
Expand Down Expand Up @@ -164,21 +168,24 @@ In this scenario, consuming the `OnMelted` event will trigger a transition which
4. `Node` Liquid OnEnter

## Decision States
![Even-Odd Diagram](examples/even-odd/state-diagram.png)

If you include a `decision` in a state definition, it will be executed in preference to the normal `onEnter`. The return value from the
decision lambda will be processed as if `consume()` had been called, with all the normal event handling / transition rules. A return
value `null` or other unhandled event wont cause a transition.

```kotlin
graph {
initialState(StateA)
state(StateA) {
allows(StateB)
}

state(StateA) { allows(StateB) }

state(StateB) {
decision { /* returns an event, or null */ }
on(TestEvent) { transitionTo(StateA) }
on(OtherTestEvent) { transitionTo(StateC) }
}

state(StateC)
}
```
Expand Down Expand Up @@ -295,4 +302,4 @@ val stateMachine = graph {
// called with each state we land in eg, Solid or Gas
}
}
```
```
Binary file added examples/even-odd/state-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a928124

Please sign in to comment.