reduxkotlin-thunk

Redux thunmk implementation for Redux-Kotlin. Mulitiplatform supported.

License

License

Categories

Categories

Kotlin Languages
GroupId

GroupId

org.reduxkotlin
ArtifactId

ArtifactId

redux-kotlin-thunk-jvm
Last Version

Last Version

0.5.5
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

reduxkotlin-thunk
Redux thunmk implementation for Redux-Kotlin. Mulitiplatform supported.
Project URL

Project URL

https://github.com/reduxkotlin/redux-kotlin-thunk/
Source Code Management

Source Code Management

https://github.com/reduxkotlin/redux-kotlin-thunk/

Download redux-kotlin-thunk-jvm

Dependencies

compile (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib jar 1.4.0
org.jetbrains.kotlin : kotlin-stdlib-common jar 1.4.0

runtime (1)

Group / Artifact Type Version
org.reduxkotlin : redux-kotlin-jvm jar 0.5.5

Project Modules

There are no modules declared in this project.

Redux-Kotlin

Test

badge badge badge badge badge badge badge badge

A redux Thunk implementation for async action dispatch. A Thunk must conform to the Thunk typealias, which is a function with 3 paramaters: dispatch, getState, & extraArg. A common use is to make a function return a Thunk. This allows passing params to the function.

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.

    val store = createStore(::reducer, applymiddleware(createThunkMiddleware()))
    
    ...
    
    fun fooThunk(query: String): Thunk<AppState> = { dispatch, getState, extraArg ->
        dispatch(FetchingFooAction)
        launch {
            val result = api.foo(query)
            if (result.isSuccessful()) {
                dispatch(FetchFooSuccess(result.payload)
            } else {
                dispatch(FetchFooFailure(result.message)
            }
        }  
    }
 
    ...
    
    fun bar() {
       dispatch(fooThunk("my query")) 
    }

How to add to project:

Artifacts are hosted on maven central. For multiplatform, add the following to your shared module:

kotlin {
  sourceSets {
        commonMain { //   <---  name may vary on your project
            dependencies {
                implementation "org.reduxkotlin:redux-kotlin-thunk:0.5.3"
            }
        }
 }

For JVM only:

  implementation "org.reduxkotlin:redux-kotlin-jvm-thunk:0.5.3"
org.reduxkotlin

Redux-Kotlin

Redux for Kotlin multiplatform

Versions

Version
0.5.5
0.5.4
0.5.3
0.4.0
0.2.9
0.2.8
0.2.7
0.2.6
0.2.5
0.2.4
0.2.3
0.2