Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ext.anko_version='0.10.8'
ext.androidx_lifecycle_version='2.0.0'
ext.rxjava2_version='2.2.8'
ext.rxkotlin_version='2.3.0'
ext.rck_version='2.0.2'
ext.rck_version='2.0.3'
```

### App's build.gradle
Expand Down
6 changes: 3 additions & 3 deletions reactcomponentkit/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ publish {
userOrg = 'skyfe79'
groupId = 'com.github.skyfe79.android'
artifactId = 'reactcomponentkit'
publishVersion = '2.0.2'
publishVersion = '2.0.3'
desc = 'AndroidReactComponentKit = Component + MVVM + Redux for Android!!!'
website = 'https://github.com/ReactComponentKit/AndroidReactComponentKit'
}
Expand All @@ -29,8 +29,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 29
versionCode 22
versionName "2.0.2"
versionCode 23
versionName "2.0.3"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.github.skyfe79.android.reactcomponentkit.rx

import com.github.skyfe79.android.reactcomponentkit.redux.State
import com.github.skyfe79.android.reactcomponentkit.viewmodel.RCKViewModel
import io.reactivex.Observable
import io.reactivex.Single
import io.reactivex.SingleEmitter
import io.reactivex.rxkotlin.subscribeBy

fun <S: State, T: Any> Single<T>.execute(success: (T) -> S): Observable<S> {
return Single.create<S> { emitter ->
this.subscribeBy(
onSuccess = {
emitter.onSuccess(success(it))
},
onError = {
emitter.onError(it)
}
)
}.toObservable()
}

fun <S: State, T: Any> Single<T>.execute(success: (T) -> S, error: SingleEmitter<S>.(Throwable) -> Unit): Observable<S> {
return Single.create<S> { emitter ->
this.subscribeBy(
onSuccess = {
emitter.onSuccess(success(it))
},
onError = {
error(emitter, it)
}
)
}.toObservable()
}

fun <S: State, T: Any> Single<T>.execute(viewModel: RCKViewModel<S>, success: S.(T) -> S): Observable<S> {
return Single.create<S> { emitter ->
this.subscribeBy(
onSuccess = {
viewModel.withState { state ->
emitter.onSuccess(success(state, it))
}
},
onError = {
emitter.onError(it)
}
)
}.toObservable()
}

fun <S: State, T: Any> Single<T>.execute(viewModel: RCKViewModel<S>, success: S.(T) -> S, error: SingleEmitter<S>.(Throwable) -> Unit): Observable<S> {
return Single.create<S> { emitter ->
this.subscribeBy(
onSuccess = {
viewModel.withState { state ->
emitter.onSuccess(success(state, it))
}
},
onError = {
error(emitter, it)
}
)
}.toObservable()
}