Skip to content
/ rxbus Public

Event bus framework supports sticky events and subscribers' priority based on RxJava 2.x

License

Notifications You must be signed in to change notification settings

ridi/rxbus

Repository files navigation

RxBus

Build Status Release

Event bus framework supports sticky events and subscribers' priority based on RxJava 3.x

Getting started

This library is distributed by jitpack.

You should add jitpack maven repository to build.gradle file of your project.

repositories {
    ...
    maven { url 'https://jitpack.io' }
    ...
}

Then you can include this library by adding dependency script to build.gradle file of your project.

dependencies {
    ...
    compile 'com.github.ridi:rxbus:<version>'
    ...
}

How to use

Defining event class

class Event(val value: Int) {
    override fun toString() = "{value=$value}"
}

Event subscription/posting

RxBus.asObservable(Event::class.java).subscribe { e ->
    System.out.println(e.toString())
}
RxBus.post(Event(0))

Output

{value=0}

Sticky events

Sticky event

RxBus.postSticky(Event(0))
RxBus.asObservable(Event::class.java, sticky = true).subscribe { e ->
    System.out.println(e.toString())
}
RxBus.post(Event(1))

Output

{value=0}
{value=1}

Subscription priority

RxBus.asObservable(Event::class.java, priority = -1).subscribe { e ->
    System.out.println("-1 Priority : $e")
}
RxBus.asObservable(Event::class.java, priority = 1).subscribe { e ->
    System.out.println("1 Priority : $e")
}
RxBus.asObservable(Event::class.java).subscribe { e ->
    System.out.println("Default(0) Priority : $e")
}
RxBus.post(Event(0))

Output

1 Priority : {value=0}
Default(0) Priority : {value=0}
-1 Priority : {value=0}

About

Event bus framework supports sticky events and subscribers' priority based on RxJava 2.x

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages