https://kotlinlang.org logo
#rx
Title
# rx
m

Mohamed Ibrahim

04/16/2019, 7:33 PM
Hello, I have a case which I need to retrieve data from local first then show it, after that retrieve data from API, then override local data, then show the updated version. I started with concat operator and it doesn't work I think because first time there is no local data to get
k

kioba

04/16/2019, 7:34 PM
concat will trigger the second stream only if the first completed
m

Mohamed Ibrahim

04/16/2019, 7:35 PM
Yes I figured that out
k

kioba

04/16/2019, 7:35 PM
try this:
Copy code
database.publish{
  Observable.concat(it.take(1), Network, it.skip(1))
}
maybe it is
share
instead of
publish
but you know the drill
m

Mohamed Ibrahim

04/16/2019, 7:36 PM
Is there any other operator that skip the first stream if it doesn't emit any data
I don't think share an publish is a good idea
k

kioba

04/16/2019, 7:38 PM
why?
u

ursus

04/16/2019, 11:56 PM
This honestly is wrong, you should always expose only local data as observable, and then have the api request only write to local -> triggering emit of the local data observable; no need to concat etc
👍 2
k

kioba

04/17/2019, 9:14 AM
yeah that is the next level, when you just observe the database changes and also trigger an event to request network which updates the database
the reason why we have a concat in our solution is if you have metadata in local database which identifies the last network request. So it will make sure we sync the data when the time comes.
m

Mohamed Ibrahim

04/23/2019, 8:12 AM
I did it with publish and merge and take until, following Kushak example in his Rxjava be examples repo
2 Views