Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xemantic/xemantic-state
Small kotlin library for transforming state beans into reactive event streams.
https://github.com/xemantic/xemantic-state
kotlin kotlin-library reactive reactive-programming reactiveui reactivex state state-management
Last synced: about 1 month ago
JSON representation
Small kotlin library for transforming state beans into reactive event streams.
- Host: GitHub
- URL: https://github.com/xemantic/xemantic-state
- Owner: xemantic
- License: lgpl-3.0
- Created: 2020-05-21T10:27:56.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-11-08T15:41:03.000Z (about 1 year ago)
- Last Synced: 2024-11-06T11:49:51.872Z (3 months ago)
- Topics: kotlin, kotlin-library, reactive, reactive-programming, reactiveui, reactivex, state, state-management
- Language: Kotlin
- Size: 136 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# xemantic-state
Small kotlin library for transforming state beans into reactive event streams. Even though small,
it has multitude of use cases in my projects.# Use cases
## Reacting to state mutations
### In UI interfaces
```kotlin
flowPanel {
button("Dock") {
actionEvents.subscribe {
state.robotMode = RobotMode.DOCKING
}
events.robotMode.subscribe { mode ->
isEnabled = mode == RobotMode.FREE
}
}
}
```See [xemantic-kotlin-swing-dsl](https://github.com/xemantic/xemantic-kotlin-swing-dsl) project
for more details
### In roboticsCollected sensor data is often a static state transmitted through the serial interface and
obtained in a busy loop. But with `xemantic-state` it can be easily upgraded to reactive event
streams delivering changes as they happen and triggering responses. It allows to avoid complexity
and conditional execution paths. Also certain classes of problems are easier to solve - especially
feedback loop based reactions. It's much easier to model certain aspects of cybernetic system
with [Functional Reactive Programming](https://en.wikipedia.org/wiki/Functional_reactive_programming)
in mind.```kotlin
events.robotMode
.filter { mode -> mode == RobotMode.DOCKING }
.doOnNext {
logger.info { "Docking" }
roomba.seekDock()
}
.flatMapMaybe {
Observables.combineLatest(events.oiMode, events.current)
.filter { pair ->
(pair.first == OiMode.PASSIVE) && (pair.second > 0)
}
.firstElement()
}
.subscribe {
state.robotMode = RobotMode.DOCKED
logger.info { "Docked" }
}
```Once robot mode changes to `DOCKING`, command the Roomba robotic vacuum cleaner to seek the dock
for charging. Roomba is not informing if the actual docking happens, therefore we wait until both -
OI mode is switching to `PASSIVE` and the electric current is positive.Imagine trying to model this as conditions in the busy loop continuously reading robot state.
## 2-way synchronization of state objects
### distributed state
### transparent use of OSC protocol
### remoting of MIDI control
# TODO
Some things are still missing:
## xemantic-state-generator module
An apt processor generating classes like:
```kotlin
class MyStateEvents(e: Events) {
val foo by e.events()
val bar by e.events()
}
```for corresponding:
```kotlin
class MyState(s: State) {
var foo by s.mutableProperty(42)
var bar by s.mutableProperty("baz")
}
```## validation
Classes passed to the `Keeper` instance, even if generated, should be
verified for correctness.