Skip to content

Commit 2c9f036

Browse files
author
Patrick Jackson
committed
update to redux 0.2.6 and use State type params
1 parent 90561ec commit 2c9f036

File tree

8 files changed

+63
-23
lines changed

8 files changed

+63
-23
lines changed

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ buildscript {
33

44
repositories {
55
google()
6+
mavenCentral()
67
maven { url 'https://dl.bintray.com/jetbrains/kotlin-native-dependencies' }
78
maven { url "https://plugins.gradle.org/m2/" }
89
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
@@ -19,10 +20,10 @@ apply from: "$rootDir/gradle/dependencies.gradle"
1920
allprojects {
2021
repositories {
2122
google()
22-
jcenter()
23+
mavenCentral()
2324
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
2425
maven { url "https://dl.bintray.com/spekframework/spek-dev" }
25-
26+
jcenter()
2627
}
2728

2829
group = GROUP

gradle/dependencies.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ ext.versions = [
22
kotlin : '1.3.41',
33
dokka : '0.9.17',
44
spek : '2.1.0-alpha.0.9+3d5d865',
5-
atrium : '0.8.0'
5+
atrium : '0.8.0',
6+
redux : '0.2.6'
67
]
78

89
ext.deps = [

gradle/wrapper/gradle-wrapper.jar

1.26 KB
Binary file not shown.
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
#Wed Apr 17 16:40:04 EDT 2019
21
distributionBase=GRADLE_USER_HOME
32
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6-rc-1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip

gradlew

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
#!/usr/bin/env sh
22

3+
#
4+
# Copyright 2015 the original author or authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
319
##############################################################################
420
##
521
## Gradle start up script for UN*X
@@ -28,7 +44,7 @@ APP_NAME="Gradle"
2844
APP_BASE_NAME=`basename "$0"`
2945

3046
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31-
DEFAULT_JVM_OPTS=""
47+
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
3248

3349
# Use the maximum available, or set MAX_FD != -1 to use that value.
3450
MAX_FD="maximum"

gradlew.bat

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
@rem
2+
@rem Copyright 2015 the original author or authors.
3+
@rem
4+
@rem Licensed under the Apache License, Version 2.0 (the "License");
5+
@rem you may not use this file except in compliance with the License.
6+
@rem You may obtain a copy of the License at
7+
@rem
8+
@rem http://www.apache.org/licenses/LICENSE-2.0
9+
@rem
10+
@rem Unless required by applicable law or agreed to in writing, software
11+
@rem distributed under the License is distributed on an "AS IS" BASIS,
12+
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
@rem See the License for the specific language governing permissions and
14+
@rem limitations under the License.
15+
@rem
16+
117
@if "%DEBUG%" == "" @echo off
218
@rem ##########################################################################
319
@rem
@@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
1430
set APP_HOME=%DIRNAME%
1531

1632
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17-
set DEFAULT_JVM_OPTS=
33+
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
1834

1935
@rem Find java.exe
2036
if defined JAVA_HOME goto findJavaFromJavaHome

lib/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ apply plugin: 'kotlin-multiplatform'
77
archivesBaseName = 'redux-kotlin-thunk'
88

99
group 'org.reduxkotlin'
10-
version '0.2.6'
10+
version '0.2.7'
1111

1212
kotlin {
1313
jvm()
@@ -60,7 +60,7 @@ kotlin {
6060
commonMain {
6161
dependencies {
6262
implementation kotlin("stdlib-common")
63-
implementation "org.reduxkotlin:redux-kotlin:0.2.4"
63+
implementation "org.reduxkotlin:redux-kotlin:$project.versions.redux"
6464
}
6565
}
6666
commonTest {

lib/src/commonMain/kotlin/org/reduxkotlin/Thunk.kt

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
package org.reduxkotlin
1+
package com.willowtreeapps.common.external
2+
3+
import org.reduxkotlin.Dispatcher
4+
import org.reduxkotlin.GetState
5+
import org.reduxkotlin.Middleware
6+
import org.reduxkotlin.Store
7+
28

39
/**
410
* Thunk middleware for async action dispatches.
@@ -17,13 +23,14 @@ package org.reduxkotlin
1723
*
1824
* store.dispatch(myNetworkThunk("query"))
1925
*/
20-
fun createThunkMiddleware(extraArgument: Any? = null): ThunkMiddleware =
21-
{ store ->
26+
@Suppress("UNCHECKED_CAST")
27+
fun <State> createThunkMiddleware(extraArgument: Any? = null): ThunkMiddleware<State> =
28+
{ store: Store<State> ->
2229
{ next: Dispatcher ->
2330
{ action: Any ->
24-
if (action is Thunk) {
31+
if (action is Thunk<*>) {
2532
try {
26-
action.dispatch(store.dispatch, store.getState, extraArgument)
33+
(action as Thunk<State>).dispatch(store.dispatch, store.getState, extraArgument)
2734
} catch (e: Exception) {
2835
// Logger.d("Dispatching functions must use type Thunk: " + e.message)
2936
throw IllegalArgumentException()
@@ -35,18 +42,17 @@ fun createThunkMiddleware(extraArgument: Any? = null): ThunkMiddleware =
3542
}
3643
}
3744

38-
typealias ThunkMiddleware = Middleware
39-
val thunk = createThunkMiddleware()
45+
typealias ThunkMiddleware<State> = Middleware<State>
4046

41-
fun ThunkMiddleware.withExtraArgument(arg: Any?) = createThunkMiddleware(arg)
47+
fun <State> ThunkMiddleware<State>.withExtraArgument(arg: Any?) = createThunkMiddleware<State>(arg)
4248

4349
/**
4450
* Interface that can be dispatched and handled by ThunkMiddleware.
4551
* Asynchronous operations and Actions may be dispatched from within a Thunk.
4652
* Due to limitation of K/N a type alias does not work currently.
4753
*/
48-
interface Thunk {
49-
fun dispatch(dispatch: Dispatcher, getState: GetState, extraArgument: Any?): Any
54+
interface Thunk<State> {
55+
fun dispatch(dispatch: Dispatcher, getState: GetState<State>, extraArgument: Any?): Any
5056
}
5157
/**
5258
* Convenience function for creating thunks.
@@ -62,16 +68,17 @@ interface Thunk {
6268
*
6369
* DEV NOTE: This will not be needed if/when typealias for Thunk works with K/N
6470
*/
65-
fun createThunk(thunkLambda: (dispatch: Dispatcher, getState: GetState, extraArgument: Any?) -> Any): Thunk {
66-
return object : Thunk {
67-
override fun dispatch(dispatch: Dispatcher, getState: GetState, extraArgument: Any?): Any =
71+
fun <State> createThunk(thunkLambda: (dispatch: Dispatcher, getState: GetState<State>, extraArgument: Any?) -> Any): Thunk<State> {
72+
return object : Thunk<State> {
73+
override fun dispatch(dispatch: Dispatcher, getState: GetState<State>, extraArgument: Any?): Any =
6874
thunkLambda(dispatch, getState, extraArgument)
6975
}
7076
}
7177

7278
/*
7379
* Unable to use Thunk as a typealias currently do to a limitation of kotlin native.
74-
* Leaving code here as a reference to revisit.
80+
* Dependent on https://youtrack.jetbrains.com/issue/KT-33149
81+
* Leaving code here as a reference to revisit once the above is fixed.
7582
* /
7683
typealias Thunk = (Dispatcher, GetState, Any?) -> Any
7784
fun createThunkMiddleware(extraArgument: Any? = null): ThunkMiddleware =

0 commit comments

Comments
 (0)