Kaskade

by gumil

gumil / Kaskade

Simplifying state management

220 Stars 6 Forks Last release: about 2 months ago (0.4.2) Apache License 2.0 295 Commits 18 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Kaskade

Build Status Download Android Arsenal codecov Codacy Badge

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.

Kaskade

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: Download )

Usage

Create the

Action
and
State
objects.

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

Kaskade
with
TestState.State1
as 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

Action
with 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)

Documentation

Check out the wiki for documentation.

Some of the topics covered are: * Coroutines * RxJava * LiveData * Handling Process Death

Sample projects

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.