Skip to content

Instantly share code, notes, and snippets.

@AAverin
Last active June 26, 2016 08:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AAverin/60f22b90192aaea5ab1c36ef6d38b798 to your computer and use it in GitHub Desktop.
Save AAverin/60f22b90192aaea5ab1c36ef6d38b798 to your computer and use it in GitHub Desktop.
RxBus gist for CleanAndroidCode article series https://medium.com/@anton.averin.dev/keep-your-droid-clean-e9c093140eb6
open class RxBus {
private val bus = SerializedSubject<BusEvent, BusEvent>(PublishSubject.create());
fun post(event: BusEvent) {
bus.onNext(event)
}
fun <T> events(type: Class<T>): Observable<T> {
return events().ofType(type)
}
fun events(): Observable<BusEvent> {
return bus.asObservable()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment