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

ubu

09/07/2018, 2:41 PM
An example:
Copy code
override fun onSatelliteClicked() {
        mapSubject.take(1).subscribe(this::toggleSatelliteMode)
    }
k

kioba

09/07/2018, 2:42 PM
this will trigger
toggleSatelliteMode
once only
u

ubu

09/07/2018, 2:43 PM
oneClick -> oneAction
a new click event -> a new subscription. that may sound crazy, I suppose 😀
k

kioba

09/07/2018, 2:47 PM
Copy code
myClickSubject.switchMap {
    mapSubject.take(1)
}.subscribe(this::toggleSatelliteMode, onError = {/* dont forget error ;) */ } )
Copy code
override fun onSatelliteClicked() {
myClickSubject.onNext(1)
}
this way you don’t have to subscribe just once and each click will take one from the map. @jeremy was right with using the SwitchMap
not sure if
take(1)
will unsubscribe from the
myClickSubject
or not
2 Views