The RxJava3 plugin provides RxJava 3 operators.
implementation("com.babylon.orbit2:orbit-rxjava3:<latest-version>")
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.
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.
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.
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.