Skip to content

Commit e3d356f

Browse files
author
Patrick Jackson
committed
use org.reduxkotlin artifacts for thunk & redux
1 parent ddfa384 commit e3d356f

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

common/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ kotlin {
3434
implementation "io.ktor:ktor-client-logging:$ktorVersion"
3535
implementation "com.russhwolf:multiplatform-settings:$multiplatformSettingsVersion"
3636
implementation "com.willowtreeapps:fuzzywuzzy-kotlin:0.1.1"
37-
implementation "org.reduxkotlin:redux-kotlin:0.2"
38-
implementation "org.reduxkotlin:redux-kotlin-thunk:0.2"
37+
implementation "org.reduxkotlin:redux-kotlin:0.2.2"
38+
implementation "org.reduxkotlin:redux-kotlin-thunk:0.2.3"
3939

4040

4141
implementation "io.ktor:ktor-client-core:$ktorVersion"

common/src/commonMain/kotlin/com/willowtreeapps/common/GameEngine.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class GameEngine(navigator: Navigator,
3030
val appStore by lazy {
3131
createStore(reducer, AppState.INITIAL_STATE, applyMiddleware(thunk,
3232
navigationMiddleware::dispatch,
33+
::logMiddleware,
34+
loggerMiddleware3,
3335
settingsMiddleware::dispatch))
3436
}
3537

common/src/commonMain/kotlin/com/willowtreeapps/common/NetworkThunks.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class NetworkThunks(private val networkContext: CoroutineContext) : CoroutineSco
2121
QuestionCategoryId.DOGS -> DogItemRepository()
2222
}
2323

24-
fun fetchItems(categoryId: QuestionCategoryId, numQuestions: Int): Thunk = { dispatch ->
24+
fun fetchItems(categoryId: QuestionCategoryId, numQuestions: Int): Thunk = { dispatch, getState, extraArgument ->
2525
val repo = repoForCategory(categoryId)
2626
Logger.d("Fetching StoreInfo and Feed")
2727
launch {

common/src/commonMain/kotlin/com/willowtreeapps/common/TimerThunks.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class TimerThunks(private val backgroundContext: CoroutineContext) : CoroutineSc
1414
* Only one timer is active at a time. If called while a timer is active, it will cancel
1515
* the timer and start the new one.
1616
*/
17-
fun startCountDownTimer(initialValue: Int): Thunk = { dispatch ->
17+
fun startCountDownTimer(initialValue: Int): Thunk = { dispatch, _, _->
1818
if (countDownTimerJob == null || countDownTimerJob?.isCompleted == true) {
1919
var localQuestionClock = initialValue
2020
Logger.d("Launching new Timer")
@@ -36,12 +36,12 @@ class TimerThunks(private val backgroundContext: CoroutineContext) : CoroutineSc
3636
}
3737
}
3838

39-
fun stopTimer(): Thunk = { dispatch ->
39+
fun stopTimer(): Thunk = { dispatch, _, _ ->
4040
countDownTimerJob?.cancel()
4141
Unit
4242
}
4343

44-
fun dispatchDelayed(delayMs: Long, action: Any): Thunk = { dispatch ->
44+
fun dispatchDelayed(delayMs: Long, action: Any): Thunk = { dispatch, _, _ ->
4545
delayedJob?.cancel()
4646
delayedJob = CoroutineScope(coroutineContext).launch {
4747
delay(delayMs)
@@ -50,7 +50,7 @@ class TimerThunks(private val backgroundContext: CoroutineContext) : CoroutineSc
5050
Unit
5151
}
5252

53-
fun cancelDelayed(): Thunk = { dispatcher ->
53+
fun cancelDelayed(): Thunk = { dispatcher, _, _ ->
5454
delayedJob?.cancel()
5555
Unit
5656
}
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
package com.willowtreeapps.common.middleware
22

3-
import org.reduxkotlin.GetState
43
import com.willowtreeapps.common.AppState
54
import com.willowtreeapps.common.Logger
6-
import org.reduxkotlin.Dispatcher
7-
import org.reduxkotlin.Middleware
8-
import org.reduxkotlin.Store
5+
import org.reduxkotlin.*
96

107
fun loggerMiddleware(getState: GetState, nextDispatcher: (Any) -> Any, action: Any): Any {
118
val result = nextDispatcher(action)
@@ -26,18 +23,14 @@ val loggerMiddleware2: Middleware =
2623
}
2724
}
2825

29-
val loggerMiddleware3 = middleWare { store, next, action ->
26+
fun logMiddleware(store: Store) = { next: Dispatcher ->
27+
{ action: Any ->
28+
next(action)
29+
}
30+
}
31+
32+
33+
val loggerMiddleware3 = middleware { store, next, action ->
3034
Logger.d("DISPATCH action: ${action::class.simpleName}: $action")
3135
next(action)
3236
}
33-
34-
fun middleWare(dispatch: (Store, Dispatcher, Any) -> Any): Middleware =
35-
{ store ->
36-
{ next ->
37-
{ action: Any ->
38-
{
39-
dispatch(store, next, action)
40-
}
41-
}
42-
}
43-
}

0 commit comments

Comments
 (0)