Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Files

Latest commit

 

History

History
90 lines (67 loc) · 2.74 KB

README.md

File metadata and controls

90 lines (67 loc) · 2.74 KB

Orbit 2 RxJava3 plugin

The RxJava3 plugin provides RxJava 3 operators.

implementation("com.babylon.orbit2:orbit-rxjava3:<latest-version>")

transformRx3Observable

fun subscribeToLocationUpdates(): Observable<LocationUpdate> { ... }

class ExampleViewModel : ContainerHost<ExampleState, ExampleSideEffect> {
    ...

    fun startLocationTracking() = orbit {
            transformRx3Observable { subscribeToLocationUpdates() }
                .reduce { state.copy(currentLocation = event) }
        }
    }
}

You can use this operator to subscribe to a hot or cold Observable. This operator acts similar to flatMap.

transformRx3Single

fun apiCall(): Single<SomeResult> { ... }
fun anotherApiCall(param: SomeResult): Single<OtherResult> { ... }

class ExampleViewModel : ContainerHost<ExampleState, ExampleSideEffect> {
    ...

    fun example() = orbit {
            transformRx3Single { apiCall() }
                .transformRx3Single { anotherApiCall(event) } // "event" is the result of the first api call
        }
    }
}

You can use this operator to subscribe to an RxJava 3 Single. This operator acts similar to flatMapSingle.

transformRx3Maybe

fun getLoggedInUser(): Maybe<User> { ... }
fun anotherApiCall(param: User): Single<OtherResult> { ... }

class ExampleViewModel : ContainerHost<ExampleState, ExampleSideEffect> {
    ...

    fun example() = orbit {
            transformRx3Maybe { getLoggedInUser() }
                .transformRx3Single { anotherApiCall(event) } // Runs the API call if the user is logged in
        }
    }
}

You can use this operator to subscribe to an RxJava 3 Maybe. This operator acts similar to flatMapMaybe.

transformRx3Completable

fun doSomeWork(): Completable { ... }

class ExampleViewModel : ContainerHost<ExampleState, ExampleSideEffect> {
    ...

    fun example() = orbit {
            transformRx3Completable { doSomeWork() }
        }
    }
}

You can use this operator to subscribe to an RxJava 3 Completable. This operator acts similar to flatMapCompletable.