All Projects → MFlisar → Rxbus2

MFlisar / Rxbus2

Licence: apache-2.0
RxJava2 based bus with queuing (e.g. lifecycle based) support

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Rxbus2

ReactiveBus
🚍 Reactive Event Bus for JVM (1.7+) and Android apps built with RxJava 2
Stars: ✭ 17 (-85.34%)
Mutual labels:  bus, eventbus, rxjava2
RXBus
RX based bus with lifecycle based queuing support
Stars: ✭ 53 (-54.31%)
Mutual labels:  bus, eventbus
StaticBus
🚌 A static bus use in modules.
Stars: ✭ 15 (-87.07%)
Mutual labels:  bus, eventbus
Kotlinmvpsamples
🚀(Kotlin 版 )快速搭建 Kotlin + MVP + RxJava + Retrofit + EventBus 的框架,方便快速开发新项目、减少开发成本。
Stars: ✭ 103 (-11.21%)
Mutual labels:  rxjava2, eventbus
MVPSamples
🚀(Java 版)快速搭建 MVP + RxJava + Retrofit + EventBus 的框架,方便快速开发新项目、减少开发成本。
Stars: ✭ 113 (-2.59%)
Mutual labels:  eventbus, rxjava2
use-bus
React hook to subscribe and dispatch events accros React components
Stars: ✭ 51 (-56.03%)
Mutual labels:  bus, eventbus
Multiplatform-Bus
Kotlin event-bus compatible with Android & native iOS
Stars: ✭ 43 (-62.93%)
Mutual labels:  bus, eventbus
Rxbus
🚌 The RxBus as steady as an old dog.
Stars: ✭ 334 (+187.93%)
Mutual labels:  rxjava2, eventbus
Apollo
🚀 Awesome EventBus by RxJava.
Stars: ✭ 329 (+183.62%)
Mutual labels:  rxjava2, eventbus
Nybus
NYBus (RxBus) - A pub-sub library for Android and Java applications
Stars: ✭ 283 (+143.97%)
Mutual labels:  rxjava2, eventbus
Rxeventbus
A EventBus based on RxJava2, using Retention.CLASS annotation.
Stars: ✭ 68 (-41.38%)
Mutual labels:  rxjava2, eventbus
Devring
安卓基础开发库,包含各常用模块,让开发简单点。
Stars: ✭ 414 (+256.9%)
Mutual labels:  rxjava2, eventbus
Rxbus
Android reactive event bus that simplifies communication between Presenters, Activities, Fragments, Threads, Services, etc.
Stars: ✭ 79 (-31.9%)
Mutual labels:  rxjava2, bus
Event
📢 Lightweight event manager and dispatcher implements by Go. Go实现的轻量级的事件管理、调度程序库, 支持设置监听器的优先级, 支持根据事件名称来进行一组事件的监听
Stars: ✭ 99 (-14.66%)
Mutual labels:  eventbus
Droidcon Nyc 2017 Puzzlers
RxJava and Kotlin Puzzlers! Follow our Engineering Blog for article with explanation
Stars: ✭ 105 (-9.48%)
Mutual labels:  rxjava2
Static Gtfs Manager
GUI interface for creating, editing, exporting of static GTFS data for a public transit authority
Stars: ✭ 98 (-15.52%)
Mutual labels:  bus
Rx2animations
Repository for android animations Rx2 wrapper
Stars: ✭ 95 (-18.1%)
Mutual labels:  rxjava2
Rxapp
Stars: ✭ 108 (-6.9%)
Mutual labels:  rxjava2
Busbookingui Android
Check out the new style for App Design aims for the Bus Booking Service...😉😀😁😎
Stars: ✭ 105 (-9.48%)
Mutual labels:  bus
Timer
This is a simple rxjava2/rxjava3/kotlin-flow timer
Stars: ✭ 93 (-19.83%)
Mutual labels:  rxjava2

RxBus2 Release Android Arsenal

RxBus2 - Reactive Event Bus

This is an reactive implementation of an event bus, with a few convenient functions especially useful for handling events with activities, fragments and similar.

RxJava V1: If you are looking for a version for RxJava V1, check out my RXBus

What does it do?

  • it allows you to send events to a bus
  • it allows you to subscribe to special events wherever you want
  • it allows you to queue events until an activity is resumed (to make sure views are accessable for example) and even to pause and resume events => for example, queue events while an activity is paused and emit them as soon as it get's resumed
  • it's very lightweight

Gradle (via JitPack.io)

  1. add jitpack to your project's build.gradle:
repositories {
    maven { url "https://jitpack.io" }
}
  1. add the compile statement to your module's build.gradle:
dependencies {
	implementation 'com.github.MFlisar.RxBus2:lib:<LATEST-VERSION>'
	// optinonal:
	// implementation 'com.github.MFlisar.RxBus2:lib-extension:<LATEST-VERSION>'
	// alternatively, to include ALL modules at once
    // implementation 'com.github.MFlisar:RxBus2:<LATEST-VERSION>'
}

Usage

Content

Demo

Just check out the DemoActivity, it will show the base usage and the difference between the default and the queued RxBus

Simple usage

Use the RxBusBuilder to create Subscriptions or simple Flowables. Just like following:

// Variant 1 - create a simple Flowable:
Flowable<TestEvent> simpleFlowable = RxBusBuilder.create(TestEvent.class).build();

// Variant 2 - subscribe with the BUILDER:
Disposable simpleDisposable = RxBusBuilder.create(TestEvent.class)
    .subscribe(new Consumer<TestEvent>() {
        @Override
        public void accept(TestEvent event) {
            // Event received, handle it...
           }
    });
Sending an event
// Send an event to the bus - all observers that observe this class WITHOUT a key will receive this event
RxBus.get().send(new TestEvent());
// Send an event to the bus - only observers that observe the class AND key will receive this event
RxBus.get()
    .withKey(R.id.observer_key_1)
    .send(new TestEvent());
// Send an event to the bus - all observers that either observe the class or the class AND key will receive this event
RxBus.get()
    .withKey(R.id.observer_key_1)
    .withSendToDefaultBus()
    .send(new TestEvent());
// Send an event to the bus and cast it to a specific class (a base class of multiple classes)
// This allows you to send casted objects to the bus
// so that all observers of the casted class will receive this event 
// (of course only if the cast of the send event is possible, otherwise an exception is thrown!)
RxBus.get()
    .withCast(TestEvent.class)
    .send(new SubTestEvent());

Of course you combine those functionalities as you want!

Advanced usage - QUEUING AND BINDING

You can use this library to subscribe to events and only get them when your activity is resumed, so that you can be sure views are available. Or you can just pause and resume the bus based on any logic you want. Just like following:

RxBusBuilder.create(TestEvent.class)
    // this enables the queuing mode! Passed object must implement IRxBusQueue interface, see the demo app for an example
    .withQueuing(rxBusQueue)
    .withOnNext(new Consumer<TestEvent>() {
        @Override
        public void accept(TestEvent s) {
            // activity IS resumed, you can safely update your UI for example
        }
    })
    .buildSubscription();

Additionally, you can bind the subscription to an object and afterwards call RxDisposableManager.unsubscribe(boundObject); to unsubcribe ANY subscription that was bound to boundObject just like following:

// boundObject... can be for example your activity
RxBusBuilder.create(TestEvent.class)
    // this enables the queuing mode! Passed object must implement IRXBusQueue interface, see the demo app for an example
    .withQueuing(rxBusQueue)
    .withBound(boundObject)
    .subscribe(new Consumer<TestEvent>() {
        @Override
        public void accept(TestEvent s) {
            // activity IS resumed, you can safely update your UI for example
         }
    });
// call this for example in your activities onDestroy or wherever appropriate to unsubscribe ALL subscriptions at once that are bound to the boundOBject
RxDisposableManager.unsubscribe(boundObject);
Advanced usage - KEYS

You can use this library to subscribe to events of a typ and ONLY get them when it was send to the bus with a special key (and and additionally only when your activity is resumed, as this example shows via .withQueuing()), so that you can distinct event subscriptions of the same class based on a key (the key can be an Integer or a String). Just like following:

RxBusBuilder.create(TestEvent.class)
    // this enables the binding to the key
    .withKey(R.id.observer_key_1) // you can provide multiple keys as well
    .withQueuing(rxBusQueue)
    .withBound(boundObject)
    .subscribe(new Consumer<TestEvent>() {
        @Override
        public void accept(TestEvent event) {
            // activity IS resumed, you can safely update your UI for example
        }
    });
Advanced usage - Transfrom

You can pass in a FlowableTransformer to transform the observed event to whatever you want!

FlowableTransformer<TestEvent, TestEventTransformed> transformer = new FlowableTransformer<TestEvent, TestEventTransformed>() {
    @Override
    public Observable<TestEventTransformed> apply(Flowable<TestEvent> observable) {
        return observable
                .map(new Function<TestEvent, TestEventTransformed>() {
                    @Override
                    public TestEventTransformed apply(TestEvent event) {
                        return event.transform();
                    }
                });
    }
};
RxBusBuilder.create(TestEvent.class)
    .withQueuing(rxBusQueue)
    .withBound(boundObject)
    .subscribe(new Consumer<TestEventTransformed>() {
        @Override
        public void accept(TestEventTransformed transformedEvent) {
        }
    }, transformer);
Advanced usage - Sub Classes

By default, sub class handling is disabled and you must use RxBus.withCast(BaseClass.class) to send sub classes to base class observers (and only to the base class observers). You have two other options for handling this.

  • Use RxBus.get().withSendToSuperClasses(true).send(subClassEvent) - this will send the event to all super class observers of the send event as well
  • Enable above by default via RxBusDefaults.get().setSendToSuperClassesAsWell(true) then all events that are send via RxBus.get().sendEvent(subClassEvent) are send to all super classes of the send event as well

If you enable RxBusDefaults.get().setSendToSuperClassesAsWell(true), you can still overwrite this global default value for a single event by sending the event via RxBus.get().withSendToSuperClasses(false).send(subClassEvent) o a per event base.

Helper class - RxDisposableManager

This class helps to bind Disposables to objects and offers an easy way to unsubscribe all Disposables that are bound to an object at once. You can simply use this directly via RxDisposableManager.addDisposable(boundObject, flowable) or use it directly with the RxBusBuilder via the RxBusBuilder.withBound(boundObject) which will automatically add the Disposable to the RxDisposableManager as soon as you call RxBusBuilder.subscribe(...). This will automatically add the Disposable to the RxDisposableManager when you call RxBusBuilder.subscribe(...). Afterwards you unsubscribe via RxDisposableManager.unsubscribe(boundObject);. The bound object can be an Activity or Fragment for example, but any other object as well.

Example - Direct usage

Subscription subscription = RxBusBuilder.create(...).subscribe(...);
RxDisposableManager.addDisposable(activity, subscription);

Example - RxBusBuilder

RxBusBuilder.create(...).withBound(activity)...;

Now you only have to make sure to unsubscribe again like following:

RxDisposableManager.unsubscribe(activity);

This will remove ANY subscription that is bound to activity and therefore this can be used in your activity's onDestroy method to make sure ALL subscriptions are unsubscribed at once so that you don't leak the activity.

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].