All Projects → wind0ws → rxbus2

wind0ws / rxbus2

Licence: other
Listen and handle event ,based on RxJava.

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to rxbus2

Apollo
🚀 Awesome EventBus by RxJava.
Stars: ✭ 329 (+928.13%)
Mutual labels:  rxjava, eventbus
Awesome Third Library Source Analysis
📖 Deep understanding of popular open source library source code (optimizing...)
Stars: ✭ 866 (+2606.25%)
Mutual labels:  rxjava, eventbus
Rxbus
🚌 The RxBus as steady as an old dog.
Stars: ✭ 334 (+943.75%)
Mutual labels:  rxjava, eventbus
Nybus
NYBus (RxBus) - A pub-sub library for Android and Java applications
Stars: ✭ 283 (+784.38%)
Mutual labels:  rxjava, eventbus
RxBus
🍾 标签/线程/Kotlin/自动注销的RxBus
Stars: ✭ 25 (-21.87%)
Mutual labels:  eventbus, rxbus
Geeknews
📚A pure reading App based on Material Design + MVP + RxJava2 + Retrofit + Dagger2 + Realm + Glide
Stars: ✭ 3,496 (+10825%)
Mutual labels:  rxjava, rxbus
Smartrecom
一款基于行为识别和个性化推荐的智能推荐APP,实时为你推荐音乐和电影,让你的生活更休闲,更精彩!
Stars: ✭ 663 (+1971.88%)
Mutual labels:  rxjava, eventbus
Ticket Analysis
移动端的彩票开奖查询系统
Stars: ✭ 61 (+90.63%)
Mutual labels:  rxjava, eventbus
Rxbus
Event Bus By RxJava.
Stars: ✭ 2,126 (+6543.75%)
Mutual labels:  rxjava, rxbus
Rhub
Reactive Event Hub
Stars: ✭ 66 (+106.25%)
Mutual labels:  rxjava, eventbus
ReactiveBus
🚍 Reactive Event Bus for JVM (1.7+) and Android apps built with RxJava 2
Stars: ✭ 17 (-46.87%)
Mutual labels:  rxjava, eventbus
CEventCenter
一个Android事件分发中心库,基于对象池及接口回调实现。实现类似BroadcastReceiver/RxBus/EventBus等的消息事件传递功能,用于在Activity/Fragment/Service之间的消息传递通讯。
Stars: ✭ 116 (+262.5%)
Mutual labels:  eventbus, rxbus
RXBus
RX based bus with lifecycle based queuing support
Stars: ✭ 53 (+65.63%)
Mutual labels:  rxjava, eventbus
eventbus
A threadsafe C++ implementation of the EventBus idiom
Stars: ✭ 27 (-15.62%)
Mutual labels:  eventbus
AndroidMVPArchitecture
Android MVP architecture sample project with or without RxJava and Dagger2 and Kotlin
Stars: ✭ 78 (+143.75%)
Mutual labels:  rxjava
android-online-course
Android Online Course
Stars: ✭ 22 (-31.25%)
Mutual labels:  rxjava
dropwizard-mongo
A Dropwizard bundle for MongoDB
Stars: ✭ 20 (-37.5%)
Mutual labels:  rxjava
Android-Learning-Resources
My curated list of resources for learning Android Development.
Stars: ✭ 24 (-25%)
Mutual labels:  rxjava
use-bus
React hook to subscribe and dispatch events accros React components
Stars: ✭ 51 (+59.38%)
Mutual labels:  eventbus
react-native-event-bus
Event bus for react native, cross-interface communication solution, it works on iOS and Android.
Stars: ✭ 48 (+50%)
Mutual labels:  eventbus

RxBus2

中文说明,请点这里查看.

This is seems like EventBus which intent for post and listen event but use RxJava2 inside.

Features

  • Support annotation(RxSubscribe):auto register and unregister event.
  • Support sticky event(Just like sticky broadcast).
  • Support 3 type Bus:
    • RxBus(Publish Bus)
    • BehaviorBus
    • ReplayBus

Getting started

The first step is to include RxBus2 into your project, for example, as a Gradle compile dependency:

Because of using jitpack.io,so we need add the jitpack.io repository in your root project gradle:

allprojects {
 repositories {
    jcenter()
    //...some other repo.
    maven { url "https://jitpack.io" }
 }
}

and then add RxBus2 dependency in your module gradle:

    implementation group: 'io.reactivex.rxjava2', name: 'rxjava', version: '2.x.x'
    implementation('com.jakewharton.rxrelay2:rxrelay:2.0.0'){
        exclude group: 'io.reactivex.rxjava2',module: 'rxjava'
    }
    implementation "com.github.wind0ws:rxbus2:1.1.1"
// maybe you need RxAndroid2 if you are using this on Android.
//   implementation('io.reactivex.rxjava2:rxandroid:2.x.x') {
//        exclude group: 'io.reactivex.rxjava2', module: 'rxjava'
//    }
//remember replace "2.x.x" to the latest version. You can find latest version of RxBus2 on [release page](https://github.com/wind0ws/rxbus2/releases)

seems complicated? Not at all. I just want to make your project using latest version of library and just one version. If you confused about it, just check the gradle file on this repo.

for gradle version below 3.0, just replace keyword implementation to compile

We are done for integration.

Now we write the hello world app.

Hello,World.

If you using this library on Android. Maybe you want to observe event on Main Thread(UI Thread). So in your Application onCreate you should config MainScheduler for RxBus once.

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        // if you using @RxSubscribe Annotation,and observeOn MAIN, you should config this.
        RxBus.setMainScheduler(AndroidSchedulers.mainThread());
    }
}

You can find AndroidSchedulers here RxAndroid.(This operation is optional, do this only if you want to use @RxSubscribe Annotation and observeOn MAIN THREAD.)

Annotation usage(just for RxBus)

  • write listen event method
    @RxSubscribe(observeOnThread = EventThread.MAIN)
    public void listenRxIntegerEvent(int code) {
        String text = String.format("{ Receive event: %s\nCurrent thread: %s }", code, Thread.currentThread().getId());
        Log.d("RxBus",text)
    }
    @RxSubscribe(observeOnThread = EventThread.IO,isSticky = true)
    public void listenRxStringEvent(String event) {
        final String text = String.format("{ Receive event: %s\nCurrent thread: %s }", event, Thread.currentThread().getId());
        Log.d("RxBus",text);
    }
  • register and unregister listen method
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rx_bus);
	    //some other code ...
        RxBus.getDefault().register(this);
    }

    @Override
    protected void onDestroy() {
        //auto release register with Annotation RxSubscribe.
        RxBus.getDefault().unregister(this);
        super.onDestroy();
    }
  • post event
@Override
public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btnFireEvent:
                RxBus.getDefault().post(100);//post integer event
                RxBus.getDefault().post("Hi,a string event");//post string event
		        RxBus.getDefault().post(new MyEvent("data on my event"));//post my event.
                break;
         }
 }

Common usage

for example,ReplayBus.

ReplayBus.getDefault()
                .ofType(String.class)
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String s) throws Exception {
                        String text = "{ [" + tag + "]:" + s+" }";
                        Log.d("ReplayBus”,text);
                    }
                });
  ReplayBus.getDefault().post("ReplayBus"+ RandomUtil.random(100));

Proguard

add this line into your "proguard-rules.pro" file.

If you use annotation, you need it. Don't forget keep your bean or entity in proguard too.

# For using annotation
-keepattributes *Annotation*
-keepattributes RuntimeVisibleAnnotations
-keepattributes RuntimeInvisibleAnnotations
-keepattributes RuntimeVisibleParameterAnnotations
-keepattributes RuntimeInvisibleParameterAnnotations

-keepclassmembers class ** {
    @com.threshold.rxbus2.annotation.RxSubscribe <methods>;
}
-keep enum com.threshold.rxbus2.util.EventThread { *; }

FAQ

  • What is difference among of RxBus(PublishBus)/BehaviorBus/ReplayBus?

    Please see difference of PublishSubject / BehaviorSubject / ReplaySubject from RxJava doc.Here is link:http://reactivex.io/documentation/subject.html

  • Can you demonstrate detailed?

    Please see app module in this repo,It show 3 type bus usage.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].