Created
July 22, 2018 17:45
-
-
Save therajanmaurya/3117e79af9c5358a4373dec82b0d0326 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.reactivex.Observable | |
import io.reactivex.subjects.PublishSubject | |
// Use object so we have a singleton instance | |
object RxBus { | |
private val publisher = PublishSubject.create<Any>() | |
fun publish(event: Any) { | |
publisher.onNext(event) | |
} | |
// Listen should return an Observable and not the publisher | |
// Using ofType we filter only events that match that class type | |
fun <T> listen(eventType: Class<T>): Observable<T> = publisher.ofType(eventType) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment