You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A redux Thunk implementation for async action dispatch.
15
17
A Thunk must conform to the `Thunk` typealias, which is a function with 3 paramaters: `dispatch`, `getState`, & `extraArg`.
16
18
A common use is to make a function return a `Thunk`. This allows passing params to the function.
17
19
18
20
NOTE: Before v0.4.0 `Thunk` was an interface. Kotlin 1.3.70 fixed a bug which allows using a typealias instead, which is more concise and closer to the JS implementation.
19
21
20
-
```
21
-
val store = createStore(::reducer, applymiddleware(createThunkMiddleware()))
22
-
23
-
...
24
-
25
-
fun fooThunk(query: String): Thunk<AppState> = { dispatch, getState, extraArg ->
26
-
dispatch(FetchingFooAction)
27
-
launch {
28
-
val result = api.foo(query)
29
-
if (result.isSuccessful()) {
30
-
dispatch(FetchFooSuccess(result.payload)
31
-
} else {
32
-
dispatch(FetchFooFailure(result.message)
33
-
}
34
-
}
35
-
}
36
-
37
-
...
38
-
39
-
fun bar() {
40
-
dispatch(fooThunk("my query"))
41
-
}
22
+
```kotlin
23
+
val store = createStore(::reducer, applymiddleware(createThunkMiddleware()))
0 commit comments