Skip to content

Commit df83532

Browse files
authored
Merge pull request #2 from reduxkotlin/update-thunk
update thunk to match js implementation
2 parents 3da2571 + 818232e commit df83532

File tree

2 files changed

+15
-30
lines changed

2 files changed

+15
-30
lines changed

lib/build.gradle

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

99
group 'org.reduxkotlin'
10-
version '0.2'
10+
version '0.2.1'
1111

1212
kotlin {
1313
jvm()
14-
/* JS disabled for now - need workaround for JS not supporting
15-
/* implementing function types on class for StoreEnhancerWrapper
1614
js() {
1715
[compileKotlinJs, compileTestKotlinJs].each { configuration ->
1816
configuration.kotlinOptions {
@@ -22,9 +20,6 @@ kotlin {
2220
}
2321
}
2422
}
25-
26-
*/
27-
2823
iosArm64("ios")
2924
iosX64("iosSim")
3025
macosX64("macos")
@@ -39,7 +34,7 @@ kotlin {
3934
commonMain {
4035
dependencies {
4136
implementation kotlin("stdlib-common")
42-
implementation "org.reduxkotlin:redux-kotlin:0.2"
37+
implementation "org.reduxkotlin:redux-kotlin:0.2.1"
4338
}
4439
}
4540
commonTest {
@@ -71,7 +66,6 @@ kotlin {
7166
runtimeOnly 'org.jetbrains.kotlin:kotlin-reflect'
7267
}
7368
}
74-
/*
7569
jsMain {
7670
kotlin.srcDir('src/jsMain/kotlin')
7771
dependencies {
@@ -93,17 +87,9 @@ kotlin {
9387
}
9488
}
9589

96-
*/
97-
nativeMain {
98-
kotlin.srcDir('src/nativeMain/kotlin')
99-
}
100-
10190
iosSimMain.dependsOn iosMain
10291
iosSimTest.dependsOn iosTest
10392

104-
configure([targets.ios, targets.iosSim, targets.macos, targets.win, targets.linArm32, targets.linMips32, targets.linMipsel32, targets.lin64]) {
105-
compilations.main.source(sourceSets.nativeMain)
106-
}
10793
}
10894
}
10995

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
package org.reduxkotlin
22

3-
4-
typealias Thunk = (Dispatcher) -> Any
5-
6-
7-
fun createThunkMiddleware(store: Store)=
8-
{ dispatch: Dispatcher ->
9-
{ action: Any ->
10-
if (action is Function<*>) {
11-
try {
12-
(action as Thunk)(dispatch)
13-
} catch (e: Exception) {
3+
typealias Thunk = (Dispatcher, GetState, Any?) -> Any
4+
fun createThunkMiddleware(extraArgument: Any? = null): Middleware =
5+
{ store ->
6+
{ next: Dispatcher ->
7+
{ action: Any ->
8+
if (action is Function<*>) {
9+
try {
10+
(action as Thunk)(store.dispatch, store.getState, extraArgument)
11+
} catch (e: Exception) {
1412
// Logger.d("Dispatching functions must use type Thunk: " + e.message)
13+
}
14+
} else {
15+
next(action)
1516
}
16-
} else {
17-
dispatch(action)
1817
}
1918
}
2019
}
2120

22-
val thunk = ::createThunkMiddleware
21+
val thunk = createThunkMiddleware()

0 commit comments

Comments
 (0)