https://github.com/beapp/beapp.library.bus.android
This library provides classic and sorted bus mechanism based on Rx
https://github.com/beapp/beapp.library.bus.android
android bus rx
Last synced: 9 months ago
JSON representation
This library provides classic and sorted bus mechanism based on Rx
- Host: GitHub
- URL: https://github.com/beapp/beapp.library.bus.android
- Owner: BeApp
- License: apache-2.0
- Created: 2020-01-22T13:26:03.000Z (over 6 years ago)
- Default Branch: develop
- Last Pushed: 2020-02-21T14:02:30.000Z (over 6 years ago)
- Last Synced: 2025-07-29T08:42:08.036Z (11 months ago)
- Topics: android, bus, rx
- Language: Java
- Homepage:
- Size: 74.2 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
This library provides two bus mechanism :
1. `RxBus` : A simple one based on [RxJava](https://github.com/ReactiveX/RxJava)
2. `SortedBus` : A bus with priorities on each listened event and the ability for listeners to consume the event
# Usage
For both implementation, we first have to define events :
```java
public class MessageEvent { /* Additional fields if needed */ }
```
Then, two steps are needed, according to the implementation used.
## RxBus
1. Register subscriber for a given event
```java
RxBus.getInstance().register(MessageEvent.class)
.subscribe(event -> ...,
throwable -> ...);
```
1. Post events
```java
RxBus.getInstance().send(new MessageEvent());
```
## SortedBus
1. Register subscriber for a given event with a priority
```java
SortedBus.getInstance().register(MessageEvent.class, SortedBus.PRIORITY_MEDIUM, new Executor() {
@Override
public boolean execute(MessageEvent event) {
return false; // Return true if you want to stop this event's propagation to other subscribers. False otherwise
}
});
```
2. Post events
```java
SortedBus.getInstance().send(new MessageEvent());
```
# Installation
Add jcenter's repository in your project's repositories list, then add the dependency.
```groovy
repositories {
jcenter()
}
dependencies {
implementation 'fr.beapp.bus:bus:'
}
```