https://github.com/joshuadeguzman/rxbus
A simplified event-driven library on top of Kotlin and Rx
https://github.com/joshuadeguzman/rxbus
eventbus higher-order-function kfunctions kotlin rx rxjava
Last synced: 11 months ago
JSON representation
A simplified event-driven library on top of Kotlin and Rx
- Host: GitHub
- URL: https://github.com/joshuadeguzman/rxbus
- Owner: joshuadeguzman
- License: mit
- Created: 2018-07-16T10:49:59.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-08T10:00:50.000Z (over 7 years ago)
- Last Synced: 2025-04-04T08:07:50.511Z (11 months ago)
- Topics: eventbus, higher-order-function, kfunctions, kotlin, rx, rxjava
- Language: Kotlin
- Homepage:
- Size: 155 KB
- Stars: 3
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# RxBus
A simplified event-driven library on top of Kotlin and Rx
[](http://kotlinlang.org)
[](https://github.com/ReactiveX/RxJava/releases/tag/v2.1.10)
[](https://travis-ci.org/joshuadeguzman/RxBus)
[
](./../../releases)
### Features
| Methods | Usage |
| - | - |
| subscribe``(subscriber) | Register type object as an observer |
| post(event: Any) | Passing event class to be ommitted on the observer |
| unsubscribe(subscriber: Any) | Removes registered observers from the disposables |
### Installation
```gradle
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
// Replace version with release version, e.g. 1.0.0-alpha, -SNAPSHOT
implementation 'io.jmdg:rxbus:[VERSION]'
}
```
### Create Events
```kotlin
// Events.kt
// Define your events here
// Passing data
data class ShowDataEvent(val data: String)
// No passing of data
class NoDataEvent
```
### Implement methods
```kotlin
// Activity.kt
// This defines subscriptions (eg. on onCreate)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
// Register observers
RxBus.subscribe(this) {
Log.e(tag, it.data)
}
RxBus.subscribe(this) {
callSomeMethod()
}
}
// Remove subscriptions
override fun onStop() {
super.onStop()
RxBus.unsubscribe(this)
}
override fun onDestroy() {
super.onDestroy()
RxBus.unsubscribe(this)
}
```
```kotlin
// Fragment.kt
// This sends data to event observers/subscribers
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_fragment)
bt_send_data.setOnClickListener {
RxBus.post(ShowDataEvent("Hi, this is from Fragment.kt"))
}
}
```
### License
RxBus is released under the MIT License. See [LICENSE](https://github.com/joshuadeguzman/RxBus/blob/master/LICENSE) for details.
### Contributing
1. Fork it ()
2. Create your feature branch (`git checkout -b feature/fooBar`)
3. Commit your changes (`git commit -am 'Add some fooBar'`)
4. Push to the branch (`git push origin feature/fooBar`)
5. Create a new Pull Request