Skip to content

Commit 70643f1

Browse files
author
Patrick Jackson
committed
kotlin -> 1.3.70. Change thunk to typealias and remove interface. breaking change.
1 parent d58bb9a commit 70643f1

File tree

5 files changed

+10
-101
lines changed

5 files changed

+10
-101
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ kotlin {
6464
sourceSets {
6565
commonMain { // <--- name may vary on your project
6666
dependencies {
67-
implementation "org.reduxkotlin:redux-kotlin-thunk:0.3.1"
67+
implementation "org.reduxkotlin:redux-kotlin-thunk:0.4.0"
6868
}
6969
}
7070
}
7171
```
7272

7373
For JVM only:
7474
```
75-
implementation "org.reduxkotlin:redux-kotlin-jvm-thunk:0.3.1"
75+
implementation "org.reduxkotlin:redux-kotlin-jvm-thunk:0.4.0"
7676
```
7777

7878
[badge-android]: http://img.shields.io/badge/platform-android-brightgreen.svg?style=flat

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ android.enableJetifier=true
2121
kotlin.code.style=official
2222

2323
GROUP=org.reduxkotlin
24-
VERSION_NAME=0.1.1
24+
VERSION_NAME=0.4.0
2525

2626
POM_ARTIFACT_ID=reduxkotlin-thunk
2727
POM_DESCRIPTION=Redux thunmk implementation for Redux-Kotlin. Mulitiplatform supported.

gradle/dependencies.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
ext.versions = [
2-
kotlin : '1.3.61',
2+
kotlin : '1.3.70',
33
dokka : '0.9.17',
44
spek : '2.1.0-alpha.0.9+3d5d865',
55
atrium : '0.8.0',
6-
redux : '0.3.1'
6+
redux : '0.4.0'
77
]
88

99
ext.deps = [

lib/build.gradle

Lines changed: 1 addition & 36 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.3.1'
10+
version '0.4.0'
1111

1212
kotlin {
1313
jvm()
@@ -20,41 +20,6 @@ kotlin {
2020
}
2121
}
2222
}
23-
//-module-name args are needed to prevent circular deps bug on native platforms
24-
iosArm64("ios") {
25-
compilations.main.extraOpts.addAll(["-module-name", "thunk"])
26-
}
27-
28-
iosX64("iosSim") {
29-
compilations.main.extraOpts.addAll(["-module-name", "thunk"])
30-
}
31-
macosX64("macos") {
32-
compilations.main.extraOpts.addAll(["-module-name", "thunk"])
33-
}
34-
35-
mingwX64("win") {
36-
compilations.main.extraOpts.addAll(["-module-name", "thunk"])
37-
}
38-
39-
wasm32("wasm") {
40-
compilations.main.extraOpts.addAll(["-module-name", "thunk"])
41-
}
42-
43-
linuxArm32Hfp("linArm32") {
44-
compilations.main.extraOpts.addAll(["-module-name", "thunk"])
45-
}
46-
47-
linuxMips32("linMips32") {
48-
compilations.main.extraOpts.addAll(["-module-name", "thunk"])
49-
}
50-
51-
linuxMipsel32("linMipsel32") {
52-
compilations.main.extraOpts.addAll(["-module-name", "thunk"])
53-
}
54-
55-
linuxX64("lin64") {
56-
compilations.main.extraOpts.addAll(["-module-name", "thunk"])
57-
}
5823

5924
sourceSets {
6025
commonMain {

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

Lines changed: 4 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package org.reduxkotlin
66
* val store = createStore(myReducer, initialState,
77
* applyMiddleware(thunk, myMiddleware))
88
*
9-
* val myNetworkThunk(query: String) = createThunk { dispatch, getState, extraArgument ->
9+
* fun myNetworkThunk(query: String): Thunk<AppState> = { dispatch, getState, extraArgument ->
1010
* launch {
1111
* dispatch(LoadingAction())
1212
* //do async stuff
@@ -17,71 +17,18 @@ package org.reduxkotlin
1717
*
1818
* store.dispatch(myNetworkThunk("query"))
1919
*/
20-
@Suppress("UNCHECKED_CAST")
21-
fun <State> createThunkMiddleware(extraArgument: Any? = null): ThunkMiddleware<State> =
22-
{ store: Store<State> ->
23-
{ next: Dispatcher ->
24-
{ action: Any ->
25-
if (action is Thunk<*>) {
26-
try {
27-
(action as Thunk<State>).dispatch(store.dispatch, store.getState, extraArgument)
28-
} catch (e: Exception) {
29-
// Logger.d("Dispatching functions must use type Thunk: " + e.message)
30-
throw IllegalArgumentException()
31-
}
32-
} else {
33-
next(action)
34-
}
35-
}
36-
}
37-
}
38-
20+
typealias Thunk<State> = (dispatch: Dispatcher, getState: GetState<State>, extraArg: Any?) -> Any
3921
typealias ThunkMiddleware<State> = Middleware<State>
4022

4123
fun <State> ThunkMiddleware<State>.withExtraArgument(arg: Any?) = createThunkMiddleware<State>(arg)
4224

43-
/**
44-
* Interface that can be dispatched and handled by ThunkMiddleware.
45-
* Asynchronous operations and Actions may be dispatched from within a Thunk.
46-
* Due to limitation of K/N a type alias does not work currently.
47-
*/
48-
interface Thunk<State> {
49-
fun dispatch(dispatch: Dispatcher, getState: GetState<State>, extraArgument: Any?): Any
50-
}
51-
/**
52-
* Convenience function for creating thunks.
53-
* Usage:
54-
* val myThunk = createThunk { dispatch, getState, extraArgument ->
55-
* //do async stuff
56-
* dispatch(NewAction())
57-
* }
58-
*
59-
* ....
60-
*
61-
* store.dispatch(myThunk)
62-
*
63-
* DEV NOTE: This will not be needed if/when typealias for Thunk works with K/N
64-
*/
65-
fun <State> createThunk(thunkLambda: (dispatch: Dispatcher, getState: GetState<State>, extraArgument: Any?) -> Any): Thunk<State> {
66-
return object : Thunk<State> {
67-
override fun dispatch(dispatch: Dispatcher, getState: GetState<State>, extraArgument: Any?): Any =
68-
thunkLambda(dispatch, getState, extraArgument)
69-
}
70-
}
71-
72-
/*
73-
* Unable to use Thunk as a typealias currently do to a limitation of kotlin native.
74-
* Dependent on https://youtrack.jetbrains.com/issue/KT-33149
75-
* Leaving code here as a reference to revisit once the above is fixed.
76-
* /
77-
typealias Thunk = (Dispatcher, GetState, Any?) -> Any
78-
fun createThunkMiddleware(extraArgument: Any? = null): ThunkMiddleware =
25+
fun <State> createThunkMiddleware(extraArgument: Any? = null): ThunkMiddleware<State> =
7926
{ store ->
8027
{ next: Dispatcher ->
8128
{ action: Any ->
8229
if (action is Function<*>) {
8330
try {
84-
(action as Thunk)(store.dispatch, store.getState, extraArgument)
31+
(action as Thunk<*>)(store.dispatch, store.getState, extraArgument)
8532
} catch (e: Exception) {
8633
throw IllegalArgumentException()
8734
// Logger.d("Dispatching functions must use type Thunk: " + e.message)
@@ -92,6 +39,3 @@ fun createThunkMiddleware(extraArgument: Any? = null): ThunkMiddleware =
9239
}
9340
}
9441
}
95-
*/
96-
97-

0 commit comments

Comments
 (0)