Hello. I am using the Badoo Reaktive library and t...
# multiplatform
a
Hello. I am using the Badoo Reaktive library and the shared module makes an API call and retrieves a list of items. I'd like to expose that list somehow to native android/ios so that they can observe the value when it changes. I was looking into BehaviorSubject<List<xx>> but there's no Interop for that, like there is for Observables, Singles, etc ... and I can't seem to convert the BehaviorSubject to an observable so then to call .wrap() on it. I'm a bit lost, can anyone point me in the right direction ? How do I expose the list of items i get from the API in an observable fashion so that when the value changes in KMM it also changes in native code ?
a
Indeed, currently there is not out-of-the-box interop for Subjects. One of the approaches is to expose
BehaviorObservableWrapper
(since v2.0) plus a method like
accept(Something)
in your ViewModel or equivalent. Or you can implement a wrapper on your own, similarly to
BehaviorObservableWrapper
.
a
image.png
i did it this way ... it seems to be working. really hope it's an ok way of doing it ­čśä
uuu, there's a 2.0 version out. i'm still on 1.2.3
seems a wrapper was added in 1.3.0... sheesh !
ah, no, sorry. that's a BehaviorObservableWrapper ...
a
Yes,
BehaviorObservableWrapper
was added in v2.0. It should work if you don't need to publish events from the iOS side (read only).
Also, it's not clear why you need
bookLevelObservable
? It subscribes to
bookLevelBehavorSubject
and leaks the subscription (the returned
Disposable
is unmanaged). You could just downcast as
val bookLevelObservable: Observable<...> = bookLevelBehaviorSubject
.
refresh().subscribe{}
also ignores the returned
Disposable
. Here, you could utilise DisposableScope.