├── sample
├── app
│ ├── .gitignore
│ ├── src
│ │ ├── main
│ │ │ ├── res
│ │ │ │ ├── mipmap-hdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-mdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-xhdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-xxxhdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── values
│ │ │ │ │ ├── styles.xml
│ │ │ │ │ ├── strings.xml
│ │ │ │ │ ├── colors.xml
│ │ │ │ │ ├── dimens.xml
│ │ │ │ │ └── themes.xml
│ │ │ │ ├── drawable
│ │ │ │ │ ├── ic_done_white_24dp.xml
│ │ │ │ │ ├── ic_delete_black_24dp.xml
│ │ │ │ │ ├── ic_check_circle_black_24dp.xml
│ │ │ │ │ └── ic_edit_black_24dp.xml
│ │ │ │ ├── menu
│ │ │ │ │ └── menu_edit.xml
│ │ │ │ └── layout
│ │ │ │ │ ├── view_list_item.xml
│ │ │ │ │ ├── content_list.xml
│ │ │ │ │ ├── activity_edit.xml
│ │ │ │ │ ├── activity_list.xml
│ │ │ │ │ └── activity_detail.xml
│ │ │ ├── kotlin
│ │ │ │ └── me
│ │ │ │ │ └── retty
│ │ │ │ │ └── reduxkt
│ │ │ │ │ └── sample
│ │ │ │ │ ├── data
│ │ │ │ │ └── Todo.kt
│ │ │ │ │ ├── redux
│ │ │ │ │ ├── state
│ │ │ │ │ │ └── ApplicationState.kt
│ │ │ │ │ ├── action
│ │ │ │ │ │ ├── TodoAction.kt
│ │ │ │ │ │ └── creatorproducer
│ │ │ │ │ │ │ └── TodoActionCreatorProducer.kt
│ │ │ │ │ ├── middleware
│ │ │ │ │ │ └── Logger.kt
│ │ │ │ │ ├── reducer
│ │ │ │ │ │ ├── RootReducerSet.kt
│ │ │ │ │ │ └── TodoReducerSet.kt
│ │ │ │ │ ├── Aliases.kt
│ │ │ │ │ └── store
│ │ │ │ │ │ └── Store.kt
│ │ │ │ │ ├── extend
│ │ │ │ │ └── Extensions.kt
│ │ │ │ │ ├── ListItemView.kt
│ │ │ │ │ ├── EditActivity.kt
│ │ │ │ │ ├── ListActivity.kt
│ │ │ │ │ └── DetailActivity.kt
│ │ │ └── AndroidManifest.xml
│ │ ├── test
│ │ │ └── java
│ │ │ │ └── me
│ │ │ │ └── retty
│ │ │ │ └── reduxkt
│ │ │ │ └── sample
│ │ │ │ ├── ExampleUnitTest.java
│ │ │ │ └── TodoReducerTest.kt
│ │ └── androidTest
│ │ │ └── java
│ │ │ └── me
│ │ │ └── retty
│ │ │ └── reduxkt
│ │ │ └── sample
│ │ │ └── ExampleInstrumentedTest.java
│ ├── proguard-rules.pro
│ └── build.gradle
├── settings.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── .gitignore
├── bootstrap.sh
├── README.md
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── redux-kt-core
├── src
│ └── main
│ │ └── kotlin
│ │ └── me
│ │ └── retty
│ │ └── reduxkt
│ │ ├── StateType.kt
│ │ ├── Action.kt
│ │ ├── Middleware.kt
│ │ ├── ActionCreator.kt
│ │ ├── Reducer.kt
│ │ ├── internal
│ │ └── utils
│ │ │ └── Function.kt
│ │ └── Store.kt
└── pom.xml
├── .gitignore
├── redux-kt-rxjava-bindings
├── README.md
├── pom.xml
└── src
│ └── main
│ └── kotlin
│ └── me
│ └── retty
│ └── reduxkt
│ └── bindings
│ └── rxjava
│ └── RxJavaBindings.kt
├── LICENSE
├── pom.xml
└── README.md
/sample/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/sample/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
--------------------------------------------------------------------------------
/sample/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/redux-kt-core/src/main/kotlin/me/retty/reduxkt/StateType.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt
2 |
3 | /**
4 | * Created by yusaka on 3/15/17.
5 | */
6 | interface StateType
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/RettyEng/redux-kt/HEAD/sample/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/sample/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 |
--------------------------------------------------------------------------------
/sample/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/sample/bootstrap.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | if type mvn 1>/dev/null 2>&1; then
4 | cd $(dirname $0)/.. && mvn install
5 | else
6 | echo 'Firstly, you need to install maven to install snapshot into local cache.'
7 | fi
8 |
--------------------------------------------------------------------------------
/redux-kt-core/src/main/kotlin/me/retty/reduxkt/Action.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt
2 |
3 | import kotlin.properties.Delegates
4 |
5 | /**
6 | * Created by yusaka on 3/15/17.
7 | */
8 |
9 | interface Action
10 |
11 |
12 |
--------------------------------------------------------------------------------
/redux-kt-core/src/main/kotlin/me/retty/reduxkt/Middleware.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt
2 |
3 | /**
4 | * Created by yusaka on 3/15/17.
5 | */
6 | internal typealias Dispatcher = (Action) -> Unit
7 | typealias Middleware = (State) -> (Dispatcher) -> Dispatcher
8 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.class
2 |
3 | # Mobile Tools for Java (J2ME)
4 | .mtj.tmp/
5 |
6 | # Package Files #
7 | *.war
8 | *.ear
9 |
10 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
11 | hs_err_pid*
12 |
13 | target/
14 | .idea/
15 | *.iml
16 |
--------------------------------------------------------------------------------
/sample/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Fri Aug 25 13:52:55 JST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
7 |
--------------------------------------------------------------------------------
/redux-kt-core/src/main/kotlin/me/retty/reduxkt/ActionCreator.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt
2 |
3 | /**
4 | * Created by yusaka on 3/15/17.
5 | */
6 |
7 | typealias ActionCreator = (State, Store) -> Action
8 | typealias AsyncActionCreator = (State, Store, (ActionCreator) -> Unit) -> Unit
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/data/Todo.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.data
2 |
3 | /**
4 | * Created by atsukofukui on 2017/08/25.
5 | */
6 | data class Todo(
7 | val id: Long,
8 | val name: String,
9 | val memo: String,
10 | val isDone: Boolean
11 | )
--------------------------------------------------------------------------------
/sample/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | sample
3 | Settings
4 | Done
5 |
6 | Name
7 | Memo
8 |
9 |
--------------------------------------------------------------------------------
/sample/README.md:
--------------------------------------------------------------------------------
1 | # Building sample app and installing via adb
2 |
3 | Execute following commands.
4 |
5 | ```sh
6 | ./bootstrap.sh
7 | # Create apk
8 | ./gradlew assembleDebug
9 | # Install sample to connected android device
10 | ./gradlew installDebug
11 | ```
12 |
13 | WARNING: bootstrap.sh will install redux-kt into your maven locale cache.
14 |
15 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/redux/state/ApplicationState.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.redux.state
2 |
3 | import me.retty.reduxkt.StateType
4 | import me.retty.reduxkt.sample.data.Todo
5 |
6 | /**
7 | * Created by atsukofukui on 2017/08/23.
8 | */
9 | data class ApplicationState constructor(val todos: List = emptyList()) : StateType
10 |
--------------------------------------------------------------------------------
/sample/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 | @color/colorAccent
8 | #33111111
9 |
10 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/redux/action/TodoAction.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.redux.action
2 |
3 | import me.retty.reduxkt.Action
4 |
5 | /**
6 | * Created by atsukofukui on 2017/08/23.
7 | */
8 | interface TodoAction : Action {
9 | class OnCreateTodoAction(val name: String, val memo: String) : TodoAction
10 | class OnToggleCompletedTodoAction(val id: Long) : TodoAction
11 | }
--------------------------------------------------------------------------------
/sample/app/src/main/res/drawable/ic_done_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/app/src/main/res/drawable/ic_delete_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/redux-kt-core/src/main/kotlin/me/retty/reduxkt/Reducer.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt
2 |
3 | import me.retty.reduxkt.internal.utils.comp
4 | import me.retty.reduxkt.internal.utils.curry
5 |
6 | /**
7 | * Created by yusaka on 3/14/17.
8 | */
9 |
10 | typealias Reducer = (Action, StateType) -> StateType
11 |
12 | infix fun Reducer.compose(reducer: Reducer): Reducer = { action, state ->
13 | ((this curry action) comp (reducer curry (action)))(state)
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/sample/app/src/main/res/drawable/ic_check_circle_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/sample/app/src/test/java/me/retty/reduxkt/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 |
14 | @Test
15 | public void addition_isCorrect() throws Exception {
16 | assertEquals(4, 2 + 2);
17 | }
18 | }
--------------------------------------------------------------------------------
/sample/app/src/main/res/drawable/ic_edit_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/redux-kt-rxjava-bindings/README.md:
--------------------------------------------------------------------------------
1 | // TODO: Write it without slacking
2 |
3 | Add it as a dependency.
4 |
5 | ```
6 | compile 'com.github.rettyeng.redux-kt:redux-kt-core:0.0.2-SNAPSHOT'
7 | ```
8 |
9 | Write codes like below
10 |
11 | ```
12 | val store = RxJavaBindings.newStore(
13 | initialState,
14 | { action, state -> /* reducer */ },
15 | /* middlewares */ listOf())
16 |
17 | /* Store<*>.observable is an Observable of RxJava */
18 | store.observable.subscribe {
19 | /* procedures */
20 | }
21 | ```
22 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/redux/middleware/Logger.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.redux.middleware
2 |
3 | import android.util.Log
4 | import me.retty.reduxkt.Middleware
5 | import me.retty.reduxkt.sample.redux.state.ApplicationState
6 |
7 | /**
8 | * Created by atsukofukui on 2017/08/23.
9 | */
10 | val logger: Middleware = {
11 | { dispatch ->
12 | { action ->
13 | Log.d("Logger", "dispatching action: ${action.javaClass.canonicalName}")
14 | dispatch(action)
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/sample/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 | 4dp
5 | 8dp
6 | 12dp
7 | 16dp
8 | 24dp
9 | 20sp
10 | 16sp
11 | 14sp
12 | 12sp
13 | 11sp
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sample/app/src/main/res/menu/menu_edit.xml:
--------------------------------------------------------------------------------
1 |
15 |
--------------------------------------------------------------------------------
/redux-kt-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.github.rettyeng.redux-kt
8 | redux-kt
9 | 0.0.2-SNAPSHOT
10 |
11 |
12 | redux-kt-core
13 | redux-kt-core
14 | http://maven.apache.org
15 |
16 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/redux/reducer/RootReducerSet.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.redux.reducer
2 |
3 | import me.retty.reduxkt.sample.redux.Reducer
4 | import me.retty.reduxkt.sample.redux.action.TodoAction
5 |
6 | /**
7 | * Created by atsukofukui on 2017/08/23.
8 | */
9 | class RootReducerSet {
10 | companion object {
11 | val aggregatedReducer: Reducer = { action, state ->
12 | when (action) {
13 | is TodoAction -> TodoReducerSet.aggregatedReducer(action, state)
14 | else -> state
15 | }
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/extend/Extensions.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.extend
2 |
3 | import android.app.Activity
4 | import android.view.View
5 |
6 | /**
7 | * Created by atsukofukui on 2017/08/25.
8 | */
9 | inline fun Activity.bindView(resId: Int,
10 | noinline onClick: ((View) -> Unit)? = null): Lazy =
11 | lazy {
12 | this.findViewById(resId).apply {
13 | onClick?.let {
14 | this.setOnClickListener(it)
15 | }
16 | } as T
17 | }
18 |
19 | @Suppress("UNCHECKED_CAST")
20 | fun View.findAndCast(id: Int): T = this.findViewById(id) as T
21 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/redux/Aliases.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.redux
2 |
3 | /**
4 | * Created by atsukofukui on 2017/08/23.
5 | */
6 | import me.retty.reduxkt.ActionCreator
7 | import me.retty.reduxkt.AsyncActionCreator
8 | import me.retty.reduxkt.Middleware
9 | import me.retty.reduxkt.Reducer
10 | import me.retty.reduxkt.StateSubscriber
11 | import me.retty.reduxkt.sample.redux.state.ApplicationState
12 |
13 | typealias Subscriber = StateSubscriber
14 | typealias AsyncActionCreator = AsyncActionCreator
15 | typealias ActionCreator = ActionCreator
16 | typealias Reducer = Reducer
17 | typealias Middleware = Middleware
--------------------------------------------------------------------------------
/sample/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.1.4-2'
5 | repositories {
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:2.3.0'
10 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
11 |
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | mavenLocal()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/sample/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/sample/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/sample/app/src/main/res/layout/view_list_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
11 |
16 |
17 |
21 |
22 |
--------------------------------------------------------------------------------
/sample/app/src/main/res/layout/content_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sample/app/src/androidTest/java/me/retty/reduxkt/sample/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 |
20 | @Test
21 | public void useAppContext() throws Exception {
22 | // Context of the app under test.
23 | Context appContext = InstrumentationRegistry.getTargetContext();
24 |
25 | assertEquals("me.retty.reduxkt.sample", appContext.getPackageName());
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/redux/action/creatorproducer/TodoActionCreatorProducer.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.redux.action.creatorproducer
2 |
3 | import me.retty.reduxkt.sample.redux.AsyncActionCreator
4 | import me.retty.reduxkt.sample.redux.action.TodoAction
5 |
6 | /**
7 | * Created by atsukofukui on 2017/08/23.
8 | */
9 | class TodoActionCreatorProducer {
10 | companion object {
11 | fun produceCreateTodoAction(name: String, memo: String): AsyncActionCreator = { _, _, callback ->
12 | callback { _, _ ->
13 | TodoAction.OnCreateTodoAction(name, memo)
14 |
15 | }
16 | }
17 |
18 | fun produceToggleCompletedTodoAction(id: Long): AsyncActionCreator = { _, _, callback ->
19 | callback { _, _ ->
20 | TodoAction.OnToggleCompletedTodoAction(id)
21 | }
22 | }
23 |
24 |
25 | }
26 | }
--------------------------------------------------------------------------------
/sample/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/atsukofukui/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/redux-kt-rxjava-bindings/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 | 4.0.0
5 |
6 |
7 | com.github.rettyeng.redux-kt
8 | redux-kt
9 | 0.0.2-SNAPSHOT
10 |
11 |
12 | com.github.rettyeng.redux-kt
13 | redux-kt-rxjava-bindings
14 | redux-kt-rxjava-bindings
15 | http://maven.apache.org
16 |
17 |
18 |
19 | com.github.rettyeng.redux-kt
20 | redux-kt-core
21 | ${project.parent.version}
22 |
23 |
24 | io.reactivex.rxjava2
25 | rxjava
26 | 2.1.3
27 |
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2017 Yuta Sakata
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/redux-kt-core/src/main/kotlin/me/retty/reduxkt/internal/utils/Function.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.internal.utils
2 |
3 | /**
4 | * Created by yusaka on 3/15/17.
5 | */
6 |
7 | internal infix fun ((U) -> V).comp(g: (T) -> U): (T) -> V = { arg ->
8 | this(g(arg))
9 | }
10 |
11 | internal infix fun ((A1, A2) -> R).curry(a1: A1): (A2) -> R =
12 | { a2 ->
13 | this(a1, a2)
14 | }
15 | internal infix fun ((A1, A2, A3) -> R).curry(a1: A1): (A2, A3) -> R =
16 | { a2, a3 ->
17 | this(a1, a2, a3)
18 | }
19 | internal infix fun ((A1, A2, A3, A4) -> R).curry(a1: A1): (A2, A3, A4) -> R =
20 | { a2, a3, a4 ->
21 | this(a1, a2, a3, a4)
22 | }
23 | internal infix fun
24 | ((A1, A2, A3, A4, A5) -> R).curry(a1: A1): (A2, A3, A4, A5) -> R =
25 | { a2, a3, a4, a5 ->
26 | this(a1, a2, a3, a4, a5)
27 | }
28 | internal infix fun
29 | ((A1, A2, A3, A4, A5, A6) -> R).curry(a1: A1): (A2, A3, A4, A5, A6) -> R =
30 | { a2, a3, a4, a5, a6 ->
31 | this(a1, a2, a3, a4, a5, a6)
32 | }
33 |
--------------------------------------------------------------------------------
/sample/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
14 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
29 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sample/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdkVersion 25
6 | buildToolsVersion "25.0.3"
7 | defaultConfig {
8 | applicationId "me.retty.reduxkt.sample"
9 | minSdkVersion 21
10 | targetSdkVersion 25
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | sourceSets {
22 | main.java.srcDirs += 'src/main/kotlin'
23 | }
24 | }
25 |
26 | dependencies {
27 | compile 'com.github.rettyeng.redux-kt:redux-kt-core:0.0.2-SNAPSHOT'
28 | compile fileTree(dir: 'libs', include: ['*.jar'])
29 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
30 | exclude group: 'com.android.support', module: 'support-annotations'
31 | })
32 | compile 'com.android.support:appcompat-v7:25.3.1'
33 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
34 | compile 'com.android.support:design:25.3.1'
35 | testCompile 'junit:junit:4.12'
36 | compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
37 | }
38 | repositories {
39 | mavenCentral()
40 | }
41 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/redux/reducer/TodoReducerSet.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.redux.reducer
2 |
3 | import me.retty.reduxkt.sample.data.Todo
4 | import me.retty.reduxkt.sample.redux.action.TodoAction
5 | import me.retty.reduxkt.sample.redux.state.ApplicationState
6 |
7 | /**
8 | * Created by atsukofukui on 2017/08/23.
9 | */
10 | class TodoReducerSet {
11 | companion object {
12 | fun aggregatedReducer(action: TodoAction, state: ApplicationState) = when (action) {
13 | is TodoAction.OnCreateTodoAction -> onCreateTodoAction(action, state)
14 | is TodoAction.OnToggleCompletedTodoAction -> onToggleCompletedTodoAction(action, state)
15 | else -> state
16 | }
17 |
18 | private fun onCreateTodoAction(action: TodoAction.OnCreateTodoAction, state: ApplicationState) =
19 | state.copy(todos = state.todos + Todo(state.todos.size.toLong(),
20 | action.name, action.memo, false))
21 |
22 | private fun onToggleCompletedTodoAction(action: TodoAction.OnToggleCompletedTodoAction,
23 | state: ApplicationState) =
24 | state.copy(todos= state.todos.map {
25 | if (it.id == action.id) {
26 | it.copy(isDone = !it.isDone)
27 | } else {
28 | it
29 | }
30 | })
31 | }
32 | }
--------------------------------------------------------------------------------
/sample/app/src/main/res/layout/activity_edit.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
28 |
29 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/redux/store/Store.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample.redux.store
2 |
3 | import me.retty.reduxkt.Action
4 | import me.retty.reduxkt.Store
5 | import me.retty.reduxkt.sample.redux.ActionCreator
6 | import me.retty.reduxkt.sample.redux.AsyncActionCreator
7 | import me.retty.reduxkt.sample.redux.Subscriber
8 | import me.retty.reduxkt.sample.redux.middleware.logger
9 | import me.retty.reduxkt.sample.redux.reducer.RootReducerSet
10 | import me.retty.reduxkt.sample.redux.state.ApplicationState
11 |
12 | /**
13 | * Created by atsukofukui on 2017/08/23.
14 | */
15 | object Store {
16 | private val store: Store by lazy {
17 | Store(getInitialState(),
18 | RootReducerSet.aggregatedReducer,
19 | listOf(logger))
20 | }
21 |
22 | private fun getInitialState(): ApplicationState {
23 | return ApplicationState()
24 | }
25 |
26 | fun getState(): ApplicationState = this.store.state
27 |
28 | fun subscribe(subscriber: Subscriber) = this.store.subscribe(subscriber)
29 | fun unsubscribe(subscriber: Subscriber) =
30 | this.store.unsubscribe(subscriber)
31 |
32 | fun dispatch(action: Action) = this.store.dispatch(action)
33 | fun dispatch(actionCreator: ActionCreator) =
34 | this.store.dispatch(actionCreator)
35 |
36 | fun dispatch(actionCreator: AsyncActionCreator) =
37 | this.store.dispatch(actionCreator)
38 |
39 | fun dispatch(actionCreator: AsyncActionCreator,
40 | callback: (ApplicationState) -> Unit) =
41 | this.store.dispatch(actionCreator, callback)
42 | }
--------------------------------------------------------------------------------
/sample/app/src/main/res/layout/activity_list.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
21 |
22 |
23 |
24 |
25 |
26 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/ListItemView.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample
2 |
3 | import android.content.Context
4 | import android.util.AttributeSet
5 | import android.view.LayoutInflater
6 | import android.widget.CheckBox
7 | import android.widget.LinearLayout
8 | import android.widget.TextView
9 | import me.retty.reduxkt.sample.extend.findAndCast
10 | import me.retty.reduxkt.sample.redux.action.creatorproducer.TodoActionCreatorProducer
11 | import me.retty.reduxkt.sample.redux.store.Store
12 | import kotlin.properties.Delegates
13 |
14 | /**
15 | * Created by atsukofukui on 2017/08/25.
16 | */
17 | class ListItemView : LinearLayout {
18 | constructor(context: Context?) : super(context)
19 | constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
20 | constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs,
21 | defStyleAttr)
22 |
23 | init {
24 | LayoutInflater.from(this.context).inflate(R.layout.view_list_item, this)
25 | this.findAndCast(R.id.ListItemView_checkbox).setOnClickListener {
26 | this.id?.let {
27 | Store.dispatch(TodoActionCreatorProducer.produceToggleCompletedTodoAction(this.id!!))
28 | }
29 | }
30 | }
31 |
32 | var textView by Delegates.observable("") { _, _, new ->
33 | this.findAndCast(me.retty.reduxkt.sample.R.id.ListItemView_text_view).text = new
34 | }
35 |
36 |
37 | var checkbox by Delegates.observable(false) { _, _, new ->
38 | this.findAndCast(
39 | me.retty.reduxkt.sample.R.id.ListItemView_checkbox).isChecked = new
40 | }
41 |
42 | var id: Long? = null
43 | }
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/EditActivity.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import android.support.v7.app.AppCompatActivity
7 | import android.view.Menu
8 | import android.view.MenuItem
9 | import android.widget.EditText
10 | import me.retty.reduxkt.sample.extend.bindView
11 | import me.retty.reduxkt.sample.redux.action.creatorproducer.TodoActionCreatorProducer
12 | import me.retty.reduxkt.sample.redux.store.Store
13 |
14 | /**
15 | * Created by atsukofukui on 2017/08/27.
16 | */
17 | class EditActivity : AppCompatActivity() {
18 |
19 | companion object {
20 | fun start(context: Context) {
21 | context.startActivity(Intent(context, EditActivity::class.java))
22 | }
23 | }
24 |
25 | private val nameEditText by bindView(R.id.EditActivity_edit_text_name)
26 | private val memoEditText by bindView(R.id.EditActivity_edit_text_memo)
27 |
28 | override fun onCreate(savedInstanceState: Bundle?) {
29 | super.onCreate(savedInstanceState)
30 | this.setContentView(R.layout.activity_edit)
31 | this.supportActionBar?.setDisplayHomeAsUpEnabled(true)
32 | }
33 |
34 |
35 | override fun onCreateOptionsMenu(menu: Menu): Boolean {
36 | this.menuInflater.inflate(R.menu.menu_edit, menu)
37 | return true
38 | }
39 |
40 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
41 | val id = item.itemId
42 |
43 | if (id == R.id.action_done) {
44 | Store.dispatch(TodoActionCreatorProducer.produceCreateTodoAction(
45 | this.nameEditText.text.toString(), this.memoEditText.text.toString()))
46 | this.finish()
47 | return true
48 | }
49 | if (id == R.id.home) {
50 | this.finish()
51 | return true
52 | }
53 | return super.onOptionsItemSelected(item)
54 | }
55 | }
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.github.rettyeng.redux-kt
6 | redux-kt
7 | pom
8 |
9 |
10 | UTF-8
11 | 1.1.4-3
12 |
13 |
14 | 0.0.2-SNAPSHOT
15 | redux-kt
16 | https://github.com/rettyeng/redux-kt
17 |
18 |
19 |
20 | org.jetbrains.kotlin
21 | kotlin-stdlib
22 | ${kotlin.version}
23 |
24 |
25 |
26 |
27 | ${project.basedir}/src/main/kotlin
28 |
29 |
30 |
31 | org.apache.maven.plugins
32 | maven-source-plugin
33 | 3.0.1
34 |
35 |
36 | package
37 |
38 | jar
39 |
40 |
41 |
42 |
43 |
44 |
45 | kotlin-maven-plugin
46 | org.jetbrains.kotlin
47 | ${kotlin.version}
48 |
49 |
50 |
51 | compile
52 |
53 | compile
54 |
55 |
56 |
57 |
58 | test-compile
59 |
60 | test-compile
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 | redux-kt-core
69 | redux-kt-rxjava-bindings
70 |
71 |
72 |
--------------------------------------------------------------------------------
/redux-kt-rxjava-bindings/src/main/kotlin/me/retty/reduxkt/bindings/rxjava/RxJavaBindings.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.bindings.rxjava
2 |
3 | import io.reactivex.Observable
4 | import io.reactivex.subjects.BehaviorSubject
5 | import me.retty.reduxkt.Action
6 | import me.retty.reduxkt.Middleware
7 | import me.retty.reduxkt.Reducer
8 | import me.retty.reduxkt.StateType
9 | import me.retty.reduxkt.Store
10 | import me.retty.reduxkt.StoreDelegate
11 | import java.util.WeakHashMap
12 |
13 | object RxJavaBindings {
14 | fun newStore(initialState: T, reducer: Reducer,
15 | middlewares: List>): Store =
16 | this.newStore(initialState, object : StoreDelegate {
17 | override fun getReducer(): Reducer = reducer
18 | override fun getMiddlewares(): List> = middlewares
19 | })
20 |
21 | fun newStore(initialState: T, delegate: StoreDelegate): Store {
22 | val fields = Fields(BehaviorSubject.createDefault (initialState))
23 | var store: Store? = null
24 |
25 | store = Store(initialState, object : StoreDelegate {
26 | override fun getReducer(): Reducer = delegate.getReducer()
27 |
28 | override fun getMiddlewares(): List> {
29 | val rxjavaPublisher: Middleware = { _ ->
30 | { dispatcher: (Action) -> Unit ->
31 | { action: Action ->
32 | dispatcher(action)
33 | fields.subject.onNext(store!!.state)
34 | }
35 | }
36 | }
37 | return listOf(rxjavaPublisher) + delegate.getMiddlewares()
38 | }
39 | })
40 |
41 | fieldsStore[store] = fields
42 | return store
43 | }
44 | }
45 |
46 | private class Fields(val subject: BehaviorSubject) {
47 | val observable: Observable by lazy {
48 | this.subject.hide()
49 | }
50 | }
51 |
52 | private val fieldsStore: MutableMap, Fields<*>> = WeakHashMap()
53 |
54 | val Store.observable: Observable
55 | @Suppress("unchecked_cast")
56 | get() = (fieldsStore[this] as? Fields)?.observable ?: throw IllegalStateException(
57 | "Calling accessor of observable for store that is not prepare for RxJava binding." +
58 | " Use RxJavaBindings#newStore to create instance of Store")
59 |
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/ListActivity.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import android.support.design.widget.FloatingActionButton
6 | import android.support.v7.app.AppCompatActivity
7 | import android.support.v7.widget.Toolbar
8 | import android.view.View
9 | import android.view.ViewGroup
10 | import android.widget.BaseAdapter
11 | import android.widget.ListView
12 | import me.retty.reduxkt.sample.data.Todo
13 | import me.retty.reduxkt.sample.extend.bindView
14 | import me.retty.reduxkt.sample.redux.Subscriber
15 | import me.retty.reduxkt.sample.redux.store.Store
16 |
17 | class ListActivity : AppCompatActivity() {
18 |
19 | private val listView by bindView(R.id.ListActivity_list_view)
20 | private val adapter by lazy { ListItemAdapter(this, emptyList()) }
21 | private val subscriber: Subscriber = { _, new ->
22 | this.adapter.data = new.todos
23 | this.adapter.notifyDataSetChanged()
24 | }
25 |
26 |
27 | override fun onCreate(savedInstanceState: Bundle?) {
28 | super.onCreate(savedInstanceState)
29 | this.setContentView(R.layout.activity_list)
30 | val toolbar = findViewById(R.id.toolbar) as Toolbar
31 | this.setSupportActionBar(toolbar)
32 |
33 | val fab = findViewById(R.id.fab) as FloatingActionButton
34 | fab.setOnClickListener { _ ->
35 | EditActivity.start(this)
36 | }
37 |
38 | this.listView.adapter = this.adapter
39 | Store.subscribe(this.subscriber)
40 | }
41 |
42 |
43 | override fun onDestroy() {
44 | super.onDestroy()
45 | Store.unsubscribe(this.subscriber)
46 | }
47 |
48 | }
49 |
50 | class ListItemAdapter(private val context: Context, var data: List) : BaseAdapter() {
51 |
52 | override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
53 | val element = this.data[position]
54 | val view: ListItemView = convertView as ListItemView? ?: ListItemView(this.context)
55 | view.id = element.id
56 | view.textView = element.name
57 | view.checkbox = element.isDone
58 | view.setOnClickListener {
59 | DetailActivity.start(context, position.toLong())
60 | }
61 | return view
62 | }
63 | override fun getCount(): Int = this.data.size
64 | override fun getItem(position: Int): Any = this.data[position]
65 | override fun getItemId(position: Int): Long = this.data[position].id
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/sample/app/src/main/res/layout/activity_detail.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
15 |
21 |
22 |
30 |
31 |
32 |
33 |
38 |
39 |
44 |
45 |
51 |
52 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/sample/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/sample/app/src/test/java/me/retty/reduxkt/sample/TodoReducerTest.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample
2 |
3 | import me.retty.reduxkt.Store
4 | import me.retty.reduxkt.sample.data.Todo
5 | import me.retty.reduxkt.sample.redux.action.TodoAction
6 | import me.retty.reduxkt.sample.redux.reducer.TodoReducerSet
7 | import me.retty.reduxkt.sample.redux.state.ApplicationState
8 | import org.junit.Assert
9 | import org.junit.Before
10 | import org.junit.Test
11 |
12 | /**
13 | * Created by atsukofukui on 2017/08/30.
14 | */
15 | class TodoReducerTest {
16 | var store: Store? = null
17 |
18 | @Before
19 | fun initiateStore() {
20 | this.store = Store(ApplicationState(listOf(Todo(0, "dummy name 0", "dummy memo 0", false),
21 | Todo(1, "dummy name 1", "dummy memo 1", true))),
22 | { action, state ->
23 | TodoReducerSet.aggregatedReducer(action as TodoAction, state)
24 | },
25 | listOf())
26 | }
27 |
28 | @Test
29 | fun testOnCreateTodoActionCorrectlyHandled() {
30 | var isCalled = false
31 | this.store?.subscribe { old, new ->
32 | if (old === new) {
33 | // Ignore invoking subscriber on starting subscribe
34 | return@subscribe
35 | }
36 | isCalled = true
37 | Assert.assertEquals(2, new.todos[2].id)
38 | Assert.assertEquals("dummy name 2", new.todos[2].name)
39 | Assert.assertEquals("dummy memo 2", new.todos[2].memo)
40 | Assert.assertEquals(false, new.todos[2].isDone)
41 | Assert.assertEquals(Todo(0, "dummy name 0", "dummy memo 0", false), new.todos[0])
42 | Assert.assertEquals(Todo(1, "dummy name 1", "dummy memo 1", true), new.todos[1])
43 | }
44 | this.store?.dispatch(TodoAction.OnCreateTodoAction("dummy name 2", "dummy memo 2"))
45 |
46 | Assert.assertTrue(isCalled)
47 | }
48 |
49 | @Test
50 | fun testOnToggleCompletedTodoActionCorrectlyHandled() {
51 | var isCalled = false
52 | this.store?.subscribe { old, new ->
53 | if (old === new) {
54 | // Ignore invoking subscriber on starting subscribe
55 | return@subscribe
56 | }
57 | isCalled = true
58 | Assert.assertEquals(1, new.todos[1].id)
59 | Assert.assertEquals("dummy name 1", new.todos[1].name)
60 | Assert.assertEquals("dummy memo 1", new.todos[1].memo)
61 | Assert.assertEquals(false, new.todos[1].isDone)
62 | Assert.assertEquals(Todo(0, "dummy name 0", "dummy memo 0", false), new.todos[0])
63 | }
64 | this.store?.dispatch(TodoAction.OnToggleCompletedTodoAction(1))
65 |
66 | Assert.assertTrue(isCalled)
67 | }
68 |
69 |
70 | }
--------------------------------------------------------------------------------
/redux-kt-core/src/main/kotlin/me/retty/reduxkt/Store.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt
2 |
3 | import java.util.concurrent.locks.ReentrantLock
4 | import kotlin.properties.Delegates
5 |
6 | /**
7 | * Created by yusaka on 3/15/17.
8 | */
9 |
10 | typealias StateSubscriber = (old: T, new: T) -> Unit
11 |
12 | class Store(initialState: T, private val delegate: StoreDelegate) {
13 |
14 | constructor(initialState: T, reducer: Reducer, middlewares: List>) :
15 | this(initialState, object : StoreDelegate {
16 | override fun getReducer(): Reducer = reducer
17 | override fun getMiddlewares(): List> = middlewares
18 | })
19 |
20 | var state: T by Delegates.observable(initialState) { _, old, new ->
21 | subscribers.forEach { it(old, new) }
22 | }
23 | private set
24 |
25 | private var subscribers: List> = emptyList()
26 | private val lock = ReentrantLock()
27 |
28 | private val withLock: Middleware = { _ ->
29 | { dispatcher ->
30 | { action ->
31 | if (lock.tryLock()) {
32 | try {
33 | dispatcher(action)
34 | } finally {
35 | lock.unlock()
36 | }
37 | } else {
38 | throw IllegalAccessError("Store is not allowed multithreaded dispatching")
39 | }
40 | }
41 | }
42 | }
43 |
44 | fun subscribe(subscriber: StateSubscriber) {
45 | if (this.subscribers.contains(subscriber)) {
46 | throw IllegalStateException("Trying to register duplicated subscriber")
47 | }
48 | this.subscribers += subscriber
49 | subscriber(this.state, this.state)
50 | }
51 |
52 | fun unsubscribe(subscriber: StateSubscriber) {
53 | this.subscribers -= subscriber
54 | }
55 |
56 | private val _dispatch: (Action) -> Unit = (this.delegate.getMiddlewares() + withLock).fold(
57 | { action: Action ->
58 | this.state = this.delegate.getReducer()(action, this.state)
59 | }
60 | ) { acc, middleWare ->
61 | middleWare(this.state)(acc)
62 | }
63 |
64 | fun dispatch(action: Action) {
65 | this._dispatch(action)
66 | }
67 |
68 | fun dispatch(creator: ActionCreator) {
69 | this.dispatch(creator(this.state, this))
70 | }
71 |
72 | fun dispatch(asyncCreator: AsyncActionCreator) {
73 | this.dispatch(asyncCreator, null)
74 | }
75 |
76 | fun dispatch(asyncCreator: AsyncActionCreator, callback: ((T) -> Unit)?) {
77 | asyncCreator(this.state, this) { creator ->
78 | this.dispatch(creator(this.state, this))
79 | callback?.invoke(this.state)
80 | }
81 | }
82 | }
83 |
84 | interface StoreDelegate {
85 | fun getReducer(): Reducer
86 | fun getMiddlewares(): List>
87 | }
--------------------------------------------------------------------------------
/sample/app/src/main/kotlin/me/retty/reduxkt/sample/DetailActivity.kt:
--------------------------------------------------------------------------------
1 | package me.retty.reduxkt.sample
2 |
3 | import android.content.Context
4 | import android.content.Intent
5 | import android.os.Bundle
6 | import android.support.v4.content.ContextCompat
7 | import android.support.v4.graphics.drawable.DrawableCompat
8 | import android.support.v7.app.AppCompatActivity
9 | import android.support.v7.widget.Toolbar
10 | import android.widget.ImageView
11 | import android.widget.TextView
12 | import me.retty.reduxkt.sample.extend.bindView
13 | import me.retty.reduxkt.sample.redux.Subscriber
14 | import me.retty.reduxkt.sample.redux.action.creatorproducer.TodoActionCreatorProducer
15 | import me.retty.reduxkt.sample.redux.store.Store
16 |
17 | /**
18 | * Created by atsukofukui on 2017/08/30.
19 | */
20 | class DetailActivity : AppCompatActivity() {
21 |
22 | companion object {
23 | private const val ITEM_ID_KEY = "item_id_key"
24 | fun start(context: Context, itemId: Long) {
25 | context.startActivity(Intent(context, DetailActivity::class.java).apply {
26 | this.putExtra(ITEM_ID_KEY, itemId)
27 | })
28 | }
29 | }
30 |
31 | private val itemId by lazy {
32 | this.intent.getLongExtra(ITEM_ID_KEY, -1)
33 | }
34 | private val memoTextView by bindView(R.id.DetailActivity_memo_text)
35 | private val toolbar by bindView(R.id.toolbar)
36 | private val doneButton by bindView(R.id.DetailActivity_done_image)
37 |
38 | private val subscriber: Subscriber = { _, _ ->
39 | this.setUpView()
40 | }
41 |
42 | override fun onCreate(savedInstanceState: Bundle?) {
43 | super.onCreate(savedInstanceState)
44 | this.setContentView(R.layout.activity_detail)
45 |
46 | this.setUpView()
47 | this.supportActionBar?.setDisplayHomeAsUpEnabled(true)
48 |
49 | Store.subscribe(this.subscriber)
50 | }
51 |
52 | private fun setUpView() {
53 | val todo = Store.getState().todos[this.itemId.toInt()]
54 | this.toolbar.title = todo.name
55 | this.memoTextView.text = todo.memo
56 | this.doneButton.setOnClickListener {
57 | Store.dispatch(TodoActionCreatorProducer.produceToggleCompletedTodoAction(todo.id))
58 | }
59 |
60 | val drawable = DrawableCompat.wrap(
61 | ContextCompat.getDrawable(this, R.drawable.ic_check_circle_black_24dp))
62 | DrawableCompat.setTintList(drawable,
63 | ContextCompat.getColorStateList(this,
64 | if (todo.isDone) {
65 | R.color.already_done
66 | } else {
67 | R.color.not_completed
68 | })
69 | )
70 | this.doneButton.setImageDrawable(drawable)
71 | }
72 |
73 | override fun onDestroy() {
74 | super.onDestroy()
75 | Store.unsubscribe(this.subscriber)
76 | }
77 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Redux-kt
2 | [](https://jitpack.io/#rettyeng/redux-kt)
3 |
4 | # Introduction
5 |
6 | Redux-kt is a simple [Redux](http://redux.js.org/)-like implementation for kotlin. This product is very inspired by [ReSwift](https://github.com/ReSwift/ReSwift).
7 |
8 | # Table of contents
9 |
10 | * [Simple usage](#simple-usage)
11 | - [Installation](#installation)
12 | * [Gradle](#gradle)
13 | * [Maven](#maven)
14 | - [Coding](#coding)
15 | - [Sample apps](#sample-apps)
16 | - [RxJava Bindings](#rxjava-bindings)
17 | * [Contributing](#contributing)
18 | - [Building](#building)
19 | - [Using debug build](#using-debug-build)
20 | * [Lisense](#license)
21 |
22 | # Simple usage
23 |
24 | This section explains a few steps to get started with redux-kt.
25 |
26 | ## Installation
27 |
28 | Redux-kt is distributed with jitpack.io so you can use it with build systems that can resolve dependencies with maven repositories.
29 |
30 | ### Gradle
31 |
32 | With gradle project, follow steps below to install redux-kt as a dependency.
33 |
34 | #### Add jitpack.io as a maven repository
35 |
36 | Open `build.gradle` of the target project and add repository setting.
37 |
38 | ```groovy
39 | buildscript {
40 | repositories {
41 | maven { url 'https://jitpack.io' }
42 | }
43 | }
44 | ```
45 |
46 | #### Modify dependencies
47 |
48 | Open `build.gradle` of the target project and insert redux-kt as a dependency of the target.
49 |
50 | ```groovy
51 | dependencies {
52 | compile 'com.github.rettyeng.redux-kt:redux-kt-core:0.0.2'
53 | }
54 | ```
55 |
56 | ### Maven
57 |
58 | With mvn, follow steps below to install redux-kt as a dependency.
59 |
60 | #### Add jitpack.io as a maven repository
61 |
62 | Open `pom.xml` of the target project and add `repository` tag.
63 |
64 | ```xml
65 |
66 |
67 | jitpack.io
68 | https://jitpack.io
69 |
70 |
71 | ```
72 |
73 | #### Modify dependencies
74 |
75 | Add redux-kt as a dependency of the project.
76 |
77 | ```xml
78 |
79 |
80 | com.github.rettyeng.redux-kt
81 | redux-kt-core
82 | 0.0.2
83 |
84 |
85 | ```
86 |
87 | ## Coding
88 |
89 | 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](#sample-apps).
90 |
91 | ```kotlin
92 | data class ApplicationState(val text: String = ""): StateType
93 | data class PostTextAction(val text: String): Action
94 |
95 | val reducer: Reducer = { action, state ->
96 | when(action) {
97 | is PostTextAction -> state.copy(text = action.text)
98 | else -> state.copy()
99 | }
100 | }
101 |
102 | val loggingMiddleware: Middleware = {
103 | { dispatch ->
104 | { action ->
105 | Log.d("Middleware", "dispatching action $action")
106 | dispatch(action)
107 | }
108 | }
109 | }
110 |
111 | val store = Store(ApplicationState(),
112 | reducer,
113 | listOf(loggingMiddleware))
114 |
115 | store.subscribe { old, new ->
116 | println("New state is $new")
117 | }
118 |
119 | store.dispatch(PostTextAction("foobar"))
120 | ```
121 |
122 | ## Sample apps
123 |
124 | [README](sample/README.md) of the sample.
125 |
126 | ## RxJava bindings
127 |
128 | [README](redux-kt-rxjava-bindings/README.md)
129 |
130 | # Contributing
131 |
132 | Feel free to report bugs, to create issues, or to create PRs.
133 |
134 | ## Building
135 |
136 | Install maven and run following command.
137 |
138 | ```sh
139 | mvn package
140 | ```
141 |
142 | ## Using debug build
143 |
144 | Import [jar](#building) into your project as a library or install a snapshot to local maven and use it.
145 |
146 | ### Install redux-kt into a local maven repository
147 |
148 | Use maven-plugin to install.
149 |
150 | ```sh
151 | mvn install
152 | ```
153 |
154 | ### Use the version installed into a local repository
155 |
156 | Use snapshot as a dependency.
157 |
158 | #### Gradle
159 |
160 | With gradle, repository settings is needed to use maven local cache.
161 |
162 | ```
163 | buildscript {
164 | repositories {
165 | mavenLocal()
166 | }
167 | }
168 |
169 | dependencies {
170 | compile 'com.github.rettyeng.redux-kt:redux-kt-core:0.0.2-SNAPSHOT'
171 | }
172 | ```
173 |
174 | #### Maven
175 |
176 | ```
177 |
178 |
179 | com.github.rettyeng.redux-kt
180 | redux-kt-core
181 | 0.0.2-SNAPSHOT
182 |
183 |
184 | ```
185 |
186 | # License
187 |
188 | [MIT](LICENSE)
189 |
190 |
191 |
--------------------------------------------------------------------------------
/sample/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------