All Projects → liangjingkanji → RxBus

liangjingkanji / RxBus

Licence: Apache-2.0 license
🍾 标签/线程/Kotlin/自动注销的RxBus

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to RxBus

rxbus2
Listen and handle event ,based on RxJava.
Stars: ✭ 32 (+28%)
Mutual labels:  eventbus, rxbus
CEventCenter
一个Android事件分发中心库,基于对象池及接口回调实现。实现类似BroadcastReceiver/RxBus/EventBus等的消息事件传递功能,用于在Activity/Fragment/Service之间的消息传递通讯。
Stars: ✭ 116 (+364%)
Mutual labels:  eventbus, rxbus
Milkomeda
Spring extend componets which build from experience of bussiness, let developers to develop with Spring Boot as fast as possible.(基于Spring生态打造的一系列来自业务上的快速开发模块集合。)
Stars: ✭ 117 (+368%)
Mutual labels:  eventbus
IntroduceToEclicpseVert.x
This repository contains the code of Vert.x examples contained in my articles published on platforms such as kodcu.com, medium, dzone. How to run each example is described in its readme file.
Stars: ✭ 27 (+8%)
Mutual labels:  eventbus
Messagebus
A MessageBus (CommandBus, EventBus and QueryBus) implementation in PHP7
Stars: ✭ 178 (+612%)
Mutual labels:  eventbus
Androideventbus
[DEPRECATED] A lightweight eventbus library for android, simplifies communication between Activities, Fragments, Threads, Services, etc.
Stars: ✭ 1,597 (+6288%)
Mutual labels:  eventbus
Unpeek Livedata
LiveData 数据倒灌:别问,问就是不可预期 - Perfect alternative to SingleLiveEvent, supporting multiple observers.
Stars: ✭ 208 (+732%)
Mutual labels:  eventbus
Cscore
cscore is a minimal-footprint library providing commonly used helpers & patterns for your C# projects. It can be used in both pure C# and Unity projects.
Stars: ✭ 115 (+360%)
Mutual labels:  eventbus
rabbitmq-advanced-spring-boot-starter
A generic library for messaging with rabbit mq with extension on spring boot amqp
Stars: ✭ 85 (+240%)
Mutual labels:  eventbus
Readhub
ReadHub Client 非官方客户端
Stars: ✭ 179 (+616%)
Mutual labels:  eventbus
KDispatcher
Simple and light-weight event dispatcher for Kotlin
Stars: ✭ 64 (+156%)
Mutual labels:  eventbus
Elegantbus
🔥🔥Android 平台,基于LivaData的EventBus,无侵入,更优雅,支持跨进程,跨应用粘性事件,自定义事件等功能。
Stars: ✭ 156 (+524%)
Mutual labels:  eventbus
Router
Router —— A substitute good of EventBus similar implemented by dynamic proxy
Stars: ✭ 147 (+488%)
Mutual labels:  eventbus
Liveeventbus
📬EventBus for Android,消息总线,基于LiveData,具有生命周期感知能力,支持Sticky,支持AndroidX,支持跨进程,支持跨APP
Stars: ✭ 3,192 (+12668%)
Mutual labels:  eventbus
Eventbus
C# 事件总线实现
Stars: ✭ 127 (+408%)
Mutual labels:  eventbus
AndroidStarterAlt
A sample View-based Android app using the MVP architecture. It uses Mosby, Dagger2, RxJava, retrofit, LoganSquare, requery, EventBus, Conductor.
Stars: ✭ 27 (+8%)
Mutual labels:  eventbus
Rxbus2
RxJava2 based bus with queuing (e.g. lifecycle based) support
Stars: ✭ 116 (+364%)
Mutual labels:  eventbus
Eventbus
eventbus实现跨进程通讯方案
Stars: ✭ 153 (+512%)
Mutual labels:  eventbus
Bus
🔊Minimalist message bus implementation for internal communication
Stars: ✭ 187 (+648%)
Mutual labels:  eventbus
green-annotations
An Android Annotations plugin to support Green Robot.
Stars: ✭ 21 (-16%)
Mutual labels:  eventbus

如果你的项目存在Kotlin推荐使用Channel

特点

  • 支持标签
  • 无需注册注销
  • 支持线程切换
  • 支持Lifecycle生命周期跟随
  • 支持Kotlin
  • 代码量最少

不支持粘性事件, 建议自己序列化到本地来控制, 市面上的粘性事件基本上都是属于全局变量, 在界面意外销毁的时候会导致数据丢失引发空指针异常.

不支持注解, 因为我认为函数比注解更加方便而且代码量更少也不存在任何性能影响, 以及便于数据共享.

安装

添加远程仓库根据创建项目的 Android Studio 版本有所不同

Android Studio Arctic Fox以下创建的项目 在项目根目录的 build.gradle 添加仓库

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

Android Studio Arctic Fox以上创建的项目 在项目根目录的 settings.gradle 添加仓库

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

然后在 module 的 build.gradle 添加依赖框架

implementation 'com.github.liangjingkanji:RxBus:1.0.2'

发送事件

sendEvent(event)

sendEvent(event, "refresh_event")

观察事件

observeEvent<Model> {
	// 事件回调
}

observeEvent<Model>("标签") {
	// 事件回调
}

建议标签采取一定规范命名, 以便全局搜索标签事件. 例如: refresh_event_event为后缀

一旦给某个事件观察者添加Tag标签. 该事件发送就必须包含标签, 否则无法接受到. (空字符串标签无效)

函数

inline fun <reified T> LifecycleOwner.observeEvent(
    vararg tags: String,
    scheduler: Scheduler = Schedulers.trampoline(),
    lifecycleEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
    noinline block: T.() -> Unit
)

标签事件

标签事件就是比一般事件多了一个字符串作为标记, 或者单纯一个标记没有事件对象.

应用场景:

  1. 某些事件你只需要通知某个界面自己刷新, 这个时候去创建一个对象作为事件来通知显得很多余.
  2. 有时候你只需要显示一个很简短的信息, 例如给上个界面发送一个Int类型的ID

示例

// 发送标签
sendTag("refresh_event")

sendEvent(123123, "refresh_event")


// 接受标签事件
observeTag("refresh_event", "finish_event"){
	when(this){
        "refresh_event" -> {}
        else -> {}
    }
}

函数

fun sendTag(tag: String)

fun LifecycleOwner.observeTag(
    vararg tags: String,
    scheduler: Scheduler = Schedulers.trampoline(),
    lifecycleEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY,
    block: String.() -> Unit
)

如果你不在Activity或者Frament中观察, 可以使用receiveTag|receiveEvent这两个函数, 他们返回Disposable用于手动注销观察者.使用方法一致

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