Skip to content

Commit e598dc8

Browse files
committed
Merge branch 'serialization'
2 parents 1384e55 + bd376ca commit e598dc8

File tree

38 files changed

+1077
-161
lines changed

38 files changed

+1077
-161
lines changed

README.md

+57-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
![KStateMachine](./docs/kstatemachine-logo.png)
22

3-
![Build and test with Gradle](https://github.com/nsk90/kstatemachine/workflows/Build%20and%20test%20with%20Gradle/badge.svg)
3+
![Build and test with Gradle](https://github.com/KStateMachine/kstatemachine/workflows/Build%20and%20test%20with%20Gradle/badge.svg)
44
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=nsk90_kstatemachine&metric=alert_status)](https://sonarcloud.io/dashboard?id=nsk90_kstatemachine)
55
[![codecov](https://codecov.io/gh/nsk90/kstatemachine/branch/master/graph/badge.svg?token=IR2JR43FOZ)](https://codecov.io/gh/nsk90/kstatemachine)
66
[![Maven Central Version](https://img.shields.io/maven-central/v/io.github.nsk90/kstatemachine?logo=sonatype)](https://central.sonatype.com/artifact/io.github.nsk90/kstatemachine)
@@ -19,7 +19,7 @@
1919
[KDoc](https://kstatemachine.github.io/kstatemachine/kdoc/index.html) |
2020
[Sponsors](#-sponsors) |
2121
[Quick start](#-quick-start-sample) |
22-
[Samples](#-samples) |
22+
[Samples](#-samples) |
2323
[Install](#-install) |
2424
[Contribution](#-contribution) |
2525
[Support](#-support) |
@@ -29,57 +29,82 @@
2929

3030
# KStateMachine
3131

32-
KStateMachine is a powerful Kotlin Multiplatform library with clean DSL syntax for creating complex [state machines](https://en.wikipedia.org/wiki/Finite-state_machine)
33-
and [statecharts](https://www.sciencedirect.com/science/article/pii/0167642387900359/pdf) driven by Kotlin Coroutines.
32+
**KStateMachine** is a powerful **Kotlin Multiplatform** library with clean DSL syntax for creating
33+
complex [state machines](https://en.wikipedia.org/wiki/Finite-state_machine)
34+
and [statecharts](https://www.sciencedirect.com/science/article/pii/0167642387900359/pdf) driven by
35+
**Kotlin Coroutines**.
3436

3537
## 🌏 Overview
3638

3739
### 📦 Integration features
3840

3941
* **[Kotlin DSL](https://kotlinlang.org/docs/type-safe-builders.html#scope-control-dslmarker) syntax** -
4042
declarative and clear state machine structure. Using without DSL is also possible.
41-
* **[Kotlin Coroutines](https://kstatemachine.github.io/kstatemachine/pages/multithreading.html#kotlin-coroutines) support** -
43+
* **[Kotlin Coroutines](https://kstatemachine.github.io/kstatemachine/pages/multithreading.html#kotlin-coroutines)
44+
support** -
4245
call suspendable functions within the library.
4346
You can fully use KStateMachine without Kotlin Coroutines dependency if necessary.
4447
* **[Kotlin Multiplatform](https://kstatemachine.github.io/kstatemachine/pages/multiplatform.html) support**
45-
* **Zero dependency** - it is written in pure Kotlin, it does not depend on any third party libraries or Android SDK.
48+
* **Zero dependency** - it is written in pure Kotlin, main library artifact does not depend on any third party libraries
49+
or Android SDK.
4650

4751
### ⚙️ State management features
4852

49-
* **[Event based](https://kstatemachine.github.io/kstatemachine/pages/events.html)** - [transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions.html) are performed by
53+
* **[Event based](https://kstatemachine.github.io/kstatemachine/pages/events.html)
54+
** - [transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions.html) are performed by
5055
processing
5156
incoming events
52-
* **[Reactive](https://kstatemachine.github.io/kstatemachine/pages/states/states.html#listen-states)** - listen for machine, states,
53-
[state groups](https://kstatemachine.github.io/kstatemachine/pages/states/states.html#listen-group-of-states) and transitions
57+
* **[Reactive](https://kstatemachine.github.io/kstatemachine/pages/states/states.html#listen-states)** - listen for
58+
machine, states,
59+
[state groups](https://kstatemachine.github.io/kstatemachine/pages/states/states.html#listen-group-of-states) and
60+
transitions
5461
* **[Guarded](https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions.html#guarded-transitions)
55-
and [Conditional transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions.html#conditional-transitions)** - dynamic
62+
and [Conditional transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions.html#conditional-transitions)
63+
** - dynamic
5664
target
5765
state which is calculated in a moment of event processing depending on application business logic
58-
* **[Nested states](https://kstatemachine.github.io/kstatemachine/pages/states/states.html#nested-states)** - build hierarchical state machines
66+
* **[Nested states](https://kstatemachine.github.io/kstatemachine/pages/states/states.html#nested-states)** - build
67+
hierarchical state machines
5968
(statecharts)
60-
with [cross-level transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions.html#cross-level-transitions) support
69+
with [cross-level transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions.html#cross-level-transitions)
70+
support
6171
* **[Composed (nested) state machines](
6272
https://kstatemachine.github.io/kstatemachine/pages/states/states.html#composed-nested-state-machines
6373
)** - use state machines as atomic child states
64-
* **[Pseudo states](https://kstatemachine.github.io/kstatemachine/pages/states/pseudo_states.html)** for additional logic in machine
74+
* **[Pseudo states](https://kstatemachine.github.io/kstatemachine/pages/states/pseudo_states.html)** for additional
75+
logic in machine
6576
behaviour
66-
* **[Typesafe transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/typesafe_transitions.html)** - pass data in
77+
* **[Typesafe transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/typesafe_transitions.html)
78+
** - pass data in
6779
typesafe way
6880
from event to state
69-
* **[Parallel states](https://kstatemachine.github.io/kstatemachine/pages/states.html#parallel-states)** - avoid a combinatorial
81+
* **[Parallel states](https://kstatemachine.github.io/kstatemachine/pages/states.html#parallel-states)** - avoid a
82+
combinatorial
7083
explosion of
7184
states
72-
* **[Undo transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions.html#undo-transitions)** - navigate back to previous
73-
state (like stack based FSMs do)
74-
* **[Optional argument](https://kstatemachine.github.io/kstatemachine/pages/events.html#event-argument)** passing for events and
85+
*
86+
*
87+
88+
*[Undo transitions](https://kstatemachine.github.io/kstatemachine/pages/transitions/transitions.html#undo-transitions)
89+
** - navigate back to previous
90+
state (like stack based FSMs do)
91+
92+
* **[Optional argument](https://kstatemachine.github.io/kstatemachine/pages/events.html#event-argument)** passing for
93+
events and
7594
transitions
7695
* **[Export](https://kstatemachine.github.io/kstatemachine/pages/export.html)** state machine structure
7796
to [PlantUML](https://plantuml.com/) and [Mermaid](https://mermaid.js.org/) diagrams
78-
* **[Persist (serialize)](https://kstatemachine.github.io/kstatemachine/pages/persistence.html)** state machine's active
79-
configuration and restore it later
80-
* **[Testable](https://kstatemachine.github.io/kstatemachine/pages/testing.html)** - run state machine from specified state and enable internal logging
81-
* **[Well tested](https://github.com/kstatemachine/kstatemachine/tree/master/tests/src/commonTest/kotlin/ru/nsk/kstatemachine)** - all features are covered
82-
by tests
97+
* **[Persist (serialize)](https://kstatemachine.github.io/kstatemachine/pages/persistence.html)** state machine's
98+
active
99+
configuration and restore it later. Built-in `kotlinx.serialization` support.
100+
* **[Testable](https://kstatemachine.github.io/kstatemachine/pages/testing.html)** - run state machine from specified
101+
state and enable internal logging
102+
*
103+
*
104+
105+
*[Well tested](https://github.com/kstatemachine/kstatemachine/tree/master/tests/src/commonTest/kotlin/ru/nsk/kstatemachine)
106+
** - all features are covered
107+
by tests
83108

84109
## 📄 Documentation
85110

@@ -93,7 +118,7 @@ I highly appreciate that you donate or become a sponsor to support the project.
93118
If you find this project useful you can support it by:
94119

95120
* Pushing the ⭐ star-button
96-
* Using ❤️github-sponsors button to see supported donation methods
121+
* Using ❤️github-sponsors button to see supported donation methods
97122

98123
## 🚀 Quick start sample
99124

@@ -125,6 +150,7 @@ object SwitchEvent : Event
125150
sealed class States : DefaultState() {
126151
object RedState : States()
127152
object YellowState : States()
153+
128154
// machine finishes when enters [FinalState]
129155
object GreenState : States(), FinalState
130156
}
@@ -152,9 +178,9 @@ fun main() = runBlocking {
152178
addState(YellowState) {
153179
transition<SwitchEvent>(targetState = GreenState)
154180
}
155-
181+
156182
addFinalState(GreenState)
157-
183+
158184
onFinished { println("Finished") }
159185
}
160186
// you can observe state machine changes using [Flow] along with simple listeners
@@ -168,14 +194,15 @@ fun main() = runBlocking {
168194

169195
## 🧪 Samples
170196

171-
* [Simple Android 2D shooter game sample](https://github.com/kstatemachine/android-kstatemachine-sample)
197+
* [Android 2D shooter game sample](https://github.com/kstatemachine/android-kstatemachine-sample)
172198

173199
The library itself does not depend on Android.
174200

175201
<p align="center">
176202
<img src="https://github.com/kstatemachine/android-kstatemachine-sample/blob/main/images/android-app-sample.gif"
177203
alt="Android sample app" width="30%" height="30%"/>
178204
</p>
205+
* [Compose 2D shooter game sample](https://github.com/KStateMachine/compose-kstatemachine-sample)
179206
* [Finished state sample](./samples/src/commonMain/kotlin/ru/nsk/samples/FinishedStateSample.kt)
180207
* [Transition on FinishedEvent sample](./samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventSample.kt)
181208
* [FinishedEvent using with DataState sample](./samples/src/commonMain/kotlin/ru/nsk/samples/FinishedEventDataStateSample.kt)
@@ -190,6 +217,7 @@ fun main() = runBlocking {
190217
* [Guarded transition sample](./samples/src/commonMain/kotlin/ru/nsk/samples/GuardedTransitionSample.kt)
191218
* [Cross-level transition sample](./samples/src/commonMain/kotlin/ru/nsk/samples/CrossLevelTransitionSample.kt)
192219
* [Typesafe transition sample](./samples/src/commonMain/kotlin/ru/nsk/samples/TypesafeTransitionSample.kt)
220+
* [Event recording sample](./samples/src/commonMain/kotlin/ru/nsk/samples/SerializationEventRecordingSample.kt)
193221
* [Complex syntax sample](./samples/src/commonMain/kotlin/ru/nsk/samples/ComplexSyntaxSample.kt)
194222
shows many syntax variants and library possibilities, so it looks messy
195223

@@ -223,11 +251,11 @@ See [CONTRIBUTING](./CONTRIBUTING.md) file.
223251
I am open to answer you questions and feature requests. Fill free to use any of communication channels to
224252
give your feedback.
225253

226-
* [Slack channel](https://kotlinlang.slack.com/archives/C07DVAEKLM8) or
254+
* [Slack channel](https://kotlinlang.slack.com/archives/C07DVAEKLM8) or
227255
[GitHub discussions](https://github.com/kstatemachine/kstatemachine/discussions) - best for questions and discussions
228256
* [GitHub issues](https://github.com/KStateMachine/kstatemachine/issues) - best for bugs and feature requests
229257

230-
If you use some other platforms to ask questions or mention the library, I recommend adding a <ins>link</ins> to this
258+
If you use some other platforms to ask questions or mention the library, I recommend adding a <ins>link</ins> to this
231259
GitHub project or using `#kstatemachine` tag.
232260

233261
## 🗺️ Roadmap

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
plugins {
22
kotlin("jvm") version Versions.kotlin apply false
33
id("org.jetbrains.dokka") version Versions.kotlinDokka
4-
id("org.jetbrains.kotlinx.binary-compatibility-validator") version Versions.kotlinBinaryCompatibilityValidator
4+
id("org.jetbrains.kotlinx.binary-compatibility-validator") version Versions.kotlinBinaryCompatibilityValidatorPlugin
55
}
66

77
group = Versions.libraryMavenCentralGroup

buildSrc/src/main/kotlin/ru/nsk/Versions.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ object Versions {
22
// library
33
const val libraryMavenCentralGroup = "io.github.nsk90"
44
const val libraryJitPackGroup = "com.github.nsk90"
5-
const val libraryVersion = "0.31.1"
5+
const val libraryVersion = "0.32.0"
66

77
// tools
8-
const val kotlin = "2.0.0"
8+
const val kotlin = "2.0.20"
99
const val kotlinDokka = "1.9.20"
10-
const val kotlinBinaryCompatibilityValidator = "0.16.3"
10+
const val kotlinBinaryCompatibilityValidatorPlugin = "0.16.3"
1111
const val jacocoTool = "0.8.11"
1212

1313
// compatibility
@@ -17,6 +17,7 @@ object Versions {
1717

1818
// dependencies
1919
const val coroutinesCore = "1.8.1"
20+
const val serialization = "1.7.3"
2021

2122
// test dependencies
2223
const val mockk = "1.13.11"

buildSrc/src/main/kotlin/ru/nsk/maven-publish.gradle.kts

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ publishing {
5050
"KStateMachine is a Kotlin DSL library for creating state machines and " +
5151
"hierarchical state machines (statecharts)."
5252
)
53-
url.set("https://github.com/nsk90/kstatemachine")
53+
url.set("https://github.com/KStateMachine/kstatemachine")
5454
inceptionYear.set("2020")
5555

5656
issueManagement {
5757
system.set("GitHub")
58-
url.set("https://github.com/nsk90/kstatemachine/issues")
58+
url.set("https://github.com/KStateMachine/kstatemachine/issues")
5959
}
6060
licenses {
6161
license {
6262
name.set("Boost Software License 1.0")
63-
url.set("https://raw.githubusercontent.com/nsk90/kstatemachine/master/LICENSE")
63+
url.set("https://raw.githubusercontent.com/KStateMachine/kstatemachine/master/LICENSE")
6464
distribution.set("repo")
6565
}
6666
}
@@ -73,9 +73,9 @@ publishing {
7373
}
7474
}
7575
scm {
76-
url.set("https://github.com/nsk90/kstatemachine")
77-
connection.set("scm:git:git://github.com/nsk90/kstatemachine.git")
78-
developerConnection.set("scm:git:ssh://[email protected]/nsk90/kstatemachine.git")
76+
url.set("https://github.com/KStateMachine/kstatemachine")
77+
connection.set("scm:git:git://github.com/KStateMachine/kstatemachine.git")
78+
developerConnection.set("scm:git:ssh://[email protected]/KStateMachine/kstatemachine.git")
7979
}
8080
}
8181
}

docs/pages/export.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ println(machine.exportToPlantUml())
4141

4242
Copy/paste resulting output to [Plant UML online editor](http://www.plantuml.com/plantuml/)
4343

44-
See [PlantUML nested states export sample](https://github.com/nsk90/kstatemachine/tree/master/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportSample.kt)
44+
See [PlantUML nested states export sample](https://github.com/KStateMachine/kstatemachine/tree/master/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportSample.kt)
4545

4646
## Mermaid
4747

@@ -60,7 +60,7 @@ println(machine.exportToMermaid())
6060
to view diagrams directly in IDE for file types: `.mmd` and `.mermaid`.
6161
* or copy/paste resulting output to [Mermaid live editor](https://mermaid.live/)
6262

63-
See [Mermaid nested states export sample](https://github.com/nsk90/kstatemachine/tree/master/samples/src/commonMain/kotlin/ru/nsk/samples/MermaidExportSample.kt)
63+
See [Mermaid nested states export sample](https://github.com/KStateMachine/kstatemachine/tree/master/samples/src/commonMain/kotlin/ru/nsk/samples/MermaidExportSample.kt)
6464

6565
## Controlling export output
6666

@@ -77,5 +77,5 @@ state("State1") {
7777
}
7878
```
7979

80-
See [PlantUML with MetaInfo export sample](https://github.com/nsk90/kstatemachine/tree/master/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportWithMetaInfoSample.kt)
80+
See [PlantUML with MetaInfo export sample](https://github.com/KStateMachine/kstatemachine/tree/master/samples/src/commonMain/kotlin/ru/nsk/samples/PlantUmlExportWithMetaInfoSample.kt)
8181

docs/pages/install.md

+16-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ title: Install
1414

1515
KStateMachine is available on `Maven Central` and `JitPack` repositories.
1616

17-
The library consists of 2 components:
17+
The library consists of the fallowing components (artifacts):
1818

19-
* `kstatemachine` - (mandatory) state machine implementation (depends only on Kotlin Standard library)
20-
* `kstatemachine-coroutines` - (optional) add-ons for working with coroutines (depends on Kotlin Coroutines library)
19+
* `kstatemachine` - (mandatory) state machine implementation (depends only on **Kotlin Standard library**)
20+
* `kstatemachine-coroutines` - (optional) add-ons for working with coroutines (depends on **Kotlin Coroutines library**)
21+
* `kstatemachine-serialization` - (optional) add-ons for serialization (depends on **Kotlin Serialization library**).
22+
Released in `v0.32.0`
2123

22-
Please note that starting from `v0.22.0` the library switched to Kotlin Multiplatform and artifact naming has changed.
24+
Please note that starting from `v0.22.0` the library switched to **Kotlin Multiplatform** and artifact naming has changed.
2325

2426
## Maven Central
2527

@@ -31,24 +33,31 @@ dependencies {
3133
// multiplatform artifacts (starting from 0.22.0)
3234
implementation("io.github.nsk90:kstatemachine:<Tag>")
3335
implementation("io.github.nsk90:kstatemachine-coroutines:<Tag>")
36+
implementation("io.github.nsk90:kstatemachine-serialization:<Tag>")
3437
// or JVM/Android artifacts (starting from 0.22.0)
3538
implementation("io.github.nsk90:kstatemachine-jvm:<Tag>")
3639
implementation("io.github.nsk90:kstatemachine-coroutines-jvm:<Tag>")
40+
implementation("io.github.nsk90:kstatemachine-serialization-jvm:<Tag>")
3741
// or iOS artifacts (starting from 0.22.1)
3842
implementation("io.github.nsk90:kstatemachine-iosarm64:<Tag>")
3943
implementation("io.github.nsk90:kstatemachine-coroutines-iosarm64:<Tag>")
44+
implementation("io.github.nsk90:kstatemachine-serialization-iosarm64:<Tag>")
4045

4146
implementation("io.github.nsk90:kstatemachine-iosx64:<Tag>")
4247
implementation("io.github.nsk90:kstatemachine-coroutines-iosx64:<Tag>")
48+
implementation("io.github.nsk90:kstatemachine-serialization-iosx64:<Tag>")
4349

4450
implementation("io.github.nsk90:kstatemachine-iossimulatorarm64:<Tag>")
4551
implementation("io.github.nsk90:kstatemachine-coroutines-iossimulatorarm64:<Tag>")
52+
implementation("io.github.nsk90:kstatemachine-serialization-iossimulatorarm64:<Tag>")
4653
// or JS
4754
implementation("io.github.nsk90:kstatemachine-js:<Tag>")
4855
implementation("io.github.nsk90:kstatemachine-coroutines-js:<Tag>")
56+
implementation("io.github.nsk90:kstatemachine-serialization-js:<Tag>")
4957
// or WebAssembly (Wasm)
5058
implementation("io.github.nsk90:kstatemachine-wasm-js:<Tag>")
5159
implementation("io.github.nsk90:kstatemachine-coroutines-wasm-js:<Tag>")
60+
implementation("io.github.nsk90:kstatemachine-serialization-wasm-js:<Tag>")
5261
}
5362
```
5463

@@ -58,6 +67,7 @@ dependencies {
5867
// multiplatform artifacts
5968
implementation 'io.github.nsk90:kstatemachine:<Tag>'
6069
implementation 'io.github.nsk90:kstatemachine-coroutines:<Tag>' // optional
70+
implementation 'io.github.nsk90:kstatemachine-serialization:<Tag>' // optional
6171
// etc..
6272
}
6373
```
@@ -104,6 +114,7 @@ dependencies {
104114
// note that group is different in second artifact, long group name also works for first artifact but not vise versa
105115
// it is some strange JitPack behaviour
106116
implementation("com.github.nsk90.kstatemachine:kstatemachine-coroutines:<Tag>") // optional
117+
implementation("com.github.nsk90.kstatemachine:kstatemachine-serialization:<Tag>") // optional
107118
}
108119
```
109120

@@ -114,6 +125,7 @@ dependencies {
114125
// note that group is different in second artifact, long group name also works for first artifact but not vise versa
115126
// it is some strange JitPack behaviour
116127
implementation 'com.github.nsk90.kstatemachine:kstatemachine-coroutines:<Tag>' // optional
128+
implementation 'com.github.nsk90.kstatemachine:kstatemachine-serialization:<Tag>' // optional
117129
}
118130
```
119131

0 commit comments

Comments
 (0)