[INACTIVE] Simplifying state management
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.
statechanges and
actiontriggers.
settings.gradle
enableFeaturePreview('GRADLE_METADATA')
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:
Create the
Actionand
Stateobjects.
Note: objects are only used here for simplicity in real projects data classes are more appropriate
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
Kaskadewith
TestState.State1as initial state ```Kotlin val kaskade = Kaskade.create(TestState.State1) { on { TestState.State1 }
on { TestState.State2 }on<testaction.action3> { TestState.State3 } </testaction.action3></testaction.action2>
} ```
Adding actions to
Actionwith parameter ActionState
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
Kotlin kaskade.stateEmitter().subscribe { // Do something with new state render(it) }
Executing actions
Kotlin kaskade.dispatch(TestAction.Action1)
Check out the wiki for documentation.
Some of the topics covered are: * Coroutines * RxJava * LiveData * Handling Process Death
Android App - Android use cases
Kotlin Console - Kotlin only project