https://github.com/gumil/kaskade
[INACTIVE] Simplifying state management
https://github.com/gumil/kaskade
android coroutines flow kaskade kotlin machine multiplatform mvi state udf unidirectional-data-flow
Last synced: 7 months ago
JSON representation
[INACTIVE] Simplifying state management
- Host: GitHub
- URL: https://github.com/gumil/kaskade
- Owner: gumil
- License: apache-2.0
- Created: 2018-02-04T04:09:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-26T21:55:11.000Z (about 5 years ago)
- Last Synced: 2024-11-03T02:32:49.055Z (12 months ago)
- Topics: android, coroutines, flow, kaskade, kotlin, machine, multiplatform, mvi, state, udf, unidirectional-data-flow
- Language: Kotlin
- Homepage:
- Size: 722 KB
- Stars: 224
- Watchers: 11
- Forks: 6
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
- awesome-kotlin-multiplatform - Kaskade - Simplifying UI state management in Kotlin Multiplatform. (Libraries / Architecture)
README
# Kaskade
[](https://travis-ci.org/gumil/Kaskade)
[](https://bintray.com/gumil/maven/kaskade/_latestVersion)
[]( https://android-arsenal.com/details/1/7421 )
[](https://codecov.io/gh/gumil/Kaskade)
[](https://www.codacy.com/app/gumil/Kaskade?utm_source=github.com&utm_medium=referral&utm_content=gumil/Kaskade&utm_campaign=Badge_Grade)
State Container for Kotlin and Android.
The name comes from cascade, a waterfall, which reflects the objective of the library to make flows easier with unidirectional data flow.
Inspired by **MVI** or **Model View Intent**.

## Why Kaskade?
* **Lightweight** - enforces unidirectional data flow without the use of external dependencies.
* **Modular** - can be easily substituted to different implementation with or without the use of another library.
* **Extendable** - in relation to modular and lightweight, it's important to extend the API and create user defined implementation to fit specific requirements.
* **Unidirectional** - data flows in one direction.
* **Predictable** - control on `state` changes and `action` triggers.
* **DSL** - able to hide complexity in a fluent way.
* **Multiplatform** - built for JVM, iOS, and Javascript.
## Installation
1. Add to **`settings.gradle`**
```
enableFeaturePreview('GRADLE_METADATA')
```
2. Add the dependency
```
dependencies {
// core module
implementation 'dev.gumil.kaskade:core:0.x.y'
// coroutines module
implementation 'dev.gumil.kaskade:coroutines:0.x.y'
// rx module
implementation 'dev.gumil.kaskade:rx:0.x.y'
// livedata module
implementation 'dev.gumil.kaskade:livedata:0.x.y'
}
```
(Please replace x and y with the latest version numbers: [](https://bintray.com/gumil/maven/kaskade/_latestVersion) )
## Usage
Create the `Action` and `State` objects.
_Note: objects are only used here for simplicity in real projects data classes are more appropriate_
```Kotlin
internal sealed class TestState : State {
object State1 : TestState()
object State2 : TestState()
object State3 : TestState()
}
internal sealed class TestAction : Action {
object Action1 : TestAction()
object Action2 : TestAction()
object Action3 : TestAction()
}
```
Create `Kaskade` with `TestState.State1` as initial state
```Kotlin
val kaskade = Kaskade.create(TestState.State1) {
on {
TestState.State1
}
on {
TestState.State2
}
on {
TestState.State3
}
}
```
Adding actions to `Action` with parameter [ActionState](kaskade/core/src/commonMain/kotlin/dev/gumil/kaskade/models.kt)
```Kotlin
on { actionState ->
// do any side effects when returning a new state
TestState.State1
}
```
Observing states
```Kotlin
kaskade.onStateChanged = {
// Do something with new state
render(it)
}
```
Observing states with [Emitter](kaskade/core/src/commonMain/kotlin/dev/gumil/kaskade/flow/Emitter.kt)
```Kotlin
kaskade.stateEmitter().subscribe {
// Do something with new state
render(it)
}
```
Executing actions
```Kotlin
kaskade.dispatch(TestAction.Action1)
```
## Documentation
Check out the [wiki](https://github.com/gumil/Kaskade/wiki) for documentation.
Some of the topics covered are:
* **[Coroutines](https://github.com/gumil/Kaskade/wiki/Coroutines)**
* **[RxJava](https://github.com/gumil/Kaskade/wiki/RxJava)**
* **[LiveData](https://github.com/gumil/Kaskade/wiki/LiveData)**
* **[Handling Process Death](https://github.com/gumil/Kaskade/wiki/Android)**
### Sample projects
* [Android App](sample/app) - Android use cases
* [auth](sample/app/src/main/kotlin/dev/gumil/kaskade/sample/auth) - Rx use case
* [network](sample/app/src/main/kotlin/dev/gumil/kaskade/sample/network) - Coroutines and LiveData use case
* [todo](sample/app/src/main/kotlin/dev/gumil/kaskade/sample/todo) - Vanilla kaskade use case
* [Kotlin Console](sample/console) - Kotlin only project
* [Giphy Android Use Case](https://github.com/gumil/giphy)
* Android master-detail
* Reactive FlowBinding and StateFlow use case