Giter VIP home page Giter VIP logo

kaskade's Introduction

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')
  1. 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

val kaskade = Kaskade.create<TestAction, TestState>(TestState.State1) {
    on<TestAction.Action1> {
        TestState.State1
    }

    on<TestAction.Action2> {
        TestState.State2
    }

    on<TestAction.Action3> {
        TestState.State3
    }
}

Adding actions to Action with parameter ActionState

on<TestAction.Action1> { actionState ->
    // do any side effects when returning a new state
    TestState.State1
}

Observing states

kaskade.onStateChanged = {
    // Do something with new state
    render(it)
}

Observing states with Emitter

kaskade.stateEmitter().subscribe {
    // Do something with new state
    render(it)
}

Executing actions

kaskade.dispatch(TestAction.Action1)

Documentation

Check out the wiki for documentation.

Some of the topics covered are:

Sample projects

kaskade's People

Contributors

gumil avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.