ursus
12/25/2018, 7:16 PMlocke
01/07/2019, 9:26 PMswitchOnNext
against an Observable<Completable>
?
Essentially I want to keep a subscription to the most recently emitted Completable
emitted by an Observable
, but for some reason that's proving challenging.Schadenfreude
01/16/2019, 5:33 PMjw
01/20/2019, 4:14 AMarekolek
01/29/2019, 10:55 AMinterface Data
data class Response(
val data: List<Data>,
val hasNextPage: Boolean,
val nextPageId: Int?
)
fun makeRequest(nextPageId: Int): Single<Response> = TODO()
fun getData(page: Int = 0): Flowable<Data> = makeRequest(page)
.flatMapPublisher {
Flowable.fromIterable(it.data)
.concatWith(it.nextPageId?.let(::getData) ?: Flowable.empty())
}
@ubu not sure how you want to do it without recursion thoughubu
01/29/2019, 10:59 AMursus
01/29/2019, 5:35 PMghedeon
02/01/2019, 11:29 AMMain
. As a result, the whole chain is now on the Main
, which is not obvious, if you look at the declaration.
Ex:
....
.map { single_that_switches_the_thread_to_Main() }
.map {} // <--- NOT io
.subscribeOn(io)
So, I'd like to be able to tell to this single_that_switches_the_thread_to_Main()
to switch to the caller thread, inside of it, not on the usage side.ghedeon
02/06/2019, 9:15 AMResult
class? In Repository as well? I see this idea popping up here and there and I just feel like it's a useless noise. There is a case when you woudn't want to break the stream on error (in UI layer, for example), but then I'd just catch the error and emit a special type of item. I'd rather do this, then wrap/unwrap the Result
everywhere. Seems like google's influence with its primitive LiveData
with no error handling support, where you have no choice other than adding exceptions to the data itself.ursus
02/14/2019, 5:34 AMursus
02/15/2019, 3:32 PMnicka
02/18/2019, 11:05 PMLoading
, Error
, or Finished
— all of which inherit from a class called: NetworkState
.
If its Loading or Error, I want to update my UI appropriately. If its finished, I need to extract the data, do further transformations, then update the UI. I also need to perform a side-effect depending on one of the values returned.
I can think of two ways to do this. Which of these is preferable? Is there a better third option?
OPTION 1
fetchFromApi().
.map {
when (it) {
is Loading -> transformToLoadingView()
is Error -> transformToErrorView()
is Finished -> mapDataToUI(it.data)
}.subscribe { view -> updateUi(view) }
fun mapDataToUI(data: Data) {
performSideEffect(data)
transformDataToView(data)
}
OPTION 2
val sharedResponse = fetchFromApi().share()
Observable.merge(
sharedResponse.ofType('Loading').map { loadingView },
sharedResponse.ofType('Error').map { errorView },
sharedResponse.ofType('Finished').map { transformDataToView(it) }
).subscribe { view -> updateUi(view) }
sharedResponse.ofType('Finished').subscribe { performSideEffect(it) }
filipradon
02/22/2019, 2:57 PMfirstOrError
to throw error if subject has no values.
@Test
fun `assert tha behaviour subject behaves like i would expect to behave`() {
BehaviorSubject.create<Boolean>()
.firstOrError()
.test()
.assertComplete()
}
jw
02/24/2019, 4:09 AMadams2
02/24/2019, 4:56 PMursus
02/26/2019, 1:02 PMursus
02/26/2019, 4:30 PMursus
02/26/2019, 4:32 PMval request = apiRequestSingle()
.map { data -> Result.Success(data) }
.onErrorReturn { throwable -> Result.Error(throwable)}
request
.flatMap { result ->
if(result is ResultSuccess) {
saveToDatabaseObservble(it)
.map { result }
} else {
Observable.just(result)
}
}
...
vs basically
apiRequestSingle()
.flatMap { data -> saveToDatabaseObservable(data)
.map { data }
}
Schadenfreude
03/05/2019, 6:44 PMedwardwongtl
03/15/2019, 5:47 AMdoOnXXX()
is intended for side effect, e.g. loggingPaul Woitaschek
03/16/2019, 9:50 AMursus
03/17/2019, 1:15 AMjw
03/23/2019, 7:48 PMCompletable
ursus
03/25/2019, 9:45 PMFredrik Larsen
04/07/2019, 9:22 PMreplay(1).autoConnect()
and the stream errs, what is the best way to not cache that error? What I would like is basically to restart the stream.ursus
04/08/2019, 8:12 PMursus
04/08/2019, 8:13 PMiex
04/09/2019, 3:18 PMkioba
04/11/2019, 5:13 PMursus
04/14/2019, 3:29 AMursus
04/14/2019, 3:29 AMwilliam
04/14/2019, 3:47 PMursus
04/15/2019, 2:37 PM