Coder Social home page Coder Social logo

redux-kt's Introduction

Redux-kt

Release

Introduction

Redux-kt is a simple Redux-like implementation for kotlin. This product is very inspired by ReSwift.

Table of contents

Simple usage

This section explains a few steps to get started with redux-kt.

Installation

Redux-kt is distributed with jitpack.io so you can use it with build systems that can resolve dependencies with maven repositories.

Gradle

With gradle project, follow steps below to install redux-kt as a dependency.

Add jitpack.io as a maven repository

Open build.gradle of the target project and add repository setting.

buildscript {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Modify dependencies

Open build.gradle of the target project and insert redux-kt as a dependency of the target.

dependencies {
    compile 'com.github.rettyeng.redux-kt:redux-kt-core:0.0.2'
}

Maven

With mvn, follow steps below to install redux-kt as a dependency.

Add jitpack.io as a maven repository

Open pom.xml of the target project and add repository tag.

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

Modify dependencies

Add redux-kt as a dependency of the project.

<dependencies>
    <dependency>
        <groupId>com.github.rettyeng.redux-kt</groupId>
        <artifactId>redux-kt-core</artifactId>
        <version>0.0.2</version>
    </dependency>
</dependencies>

Coding

A minimal example is below. If you want more examples, you can find a sample Android app project in this repository. See also Sample apps.

data class ApplicationState(val text: String = ""): StateType
data class PostTextAction(val text: String): Action

val reducer: Reducer<ApplicationState> = { action, state ->
    when(action) {
        is PostTextAction -> state.copy(text = action.text)
        else -> state.copy()
    }
}
    
val loggingMiddleware: Middleware<ApplicationState> = {
    { dispatch ->
        { action ->
            Log.d("Middleware", "dispatching action $action")
            dispatch(action)
        }
    }
}

val store = Store<ApplicationState>(ApplicationState(),
                                    reducer,
                                    listOf(loggingMiddleware))

store.subscribe { old, new ->
    println("New state is $new")
}

store.dispatch(PostTextAction("foobar"))

Sample apps

README of the sample.

RxJava bindings

README

Contributing

Feel free to report bugs, to create issues, or to create PRs.

Building

Install maven and run following command.

mvn package

Using debug build

Import jar into your project as a library or install a snapshot to local maven and use it.

Install redux-kt into a local maven repository

Use maven-plugin to install.

mvn install

Use the version installed into a local repository

Use snapshot as a dependency.

Gradle

With gradle, repository settings is needed to use maven local cache.

buildscript {
    repositories {
        mavenLocal()
    }
}

dependencies {
    compile 'com.github.rettyeng.redux-kt:redux-kt-core:0.0.2-SNAPSHOT'
}

Maven

<dependencies>
    <dependency>
        <groupId>com.github.rettyeng.redux-kt</groupId>
        <artifactId>redux-kt-core</artifactId>
        <version>0.0.2-SNAPSHOT</version>
    </dependency>
</dependencies>

License

MIT

redux-kt's People

Contributors

yusaka39 avatar

Watchers

 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.