Last active
January 19, 2020 09:10
-
-
Save esabook/f834499495e328cc762e938b8110723a to your computer and use it in GitHub Desktop.
EventBus wrapper in RxJava
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
package *** | |
import io.reactivex.subjects.PublishSubject | |
import java.util.* | |
class RxBus { | |
companion object { | |
val instance = RxBus() | |
private val subject = PublishSubject.create<Any>() | |
} | |
/** | |
* Pass any event down to event listeners. | |
*/ | |
fun post(obj: Any){ | |
subject.onNext(obj) | |
} | |
/** | |
* Subscribe to this Observable. On event, do something | |
* e.g. replace a fragment | |
*/ | |
fun getEvent(): PublishSubject<Any>? { | |
return subject | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment