https://github.com/minndevelopment/gunfire
Lightweight Event Bus for Kotlin
https://github.com/minndevelopment/gunfire
event event-emitter eventbus hierarchy kotlin lightweight
Last synced: 4 months ago
JSON representation
Lightweight Event Bus for Kotlin
- Host: GitHub
- URL: https://github.com/minndevelopment/gunfire
- Owner: MinnDevelopment
- License: apache-2.0
- Created: 2017-04-12T20:39:54.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-04-14T15:32:33.000Z (almost 9 years ago)
- Last Synced: 2025-04-14T13:28:25.913Z (10 months ago)
- Topics: event, event-emitter, eventbus, hierarchy, kotlin, lightweight
- Language: Kotlin
- Homepage:
- Size: 94.7 KB
- Stars: 17
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Project Gunfire
Project Gunfire is a lightweight event bus framework which is built in and for the Kotlin Programming Language.
This can be used to fire `bullets` with `guns`!
## Requirements
- Kotlin/JVM 1.1.1+ (including coroutines)
- Java Runtime for Java 8
### Dependencies
- Kotlinx-Coroutines for Kotlin 1.1.1+
- Kotlin std-jre8 1.1.1+
Recommended IDE: Intellij IDEA 2017.1
## Getting Started
To create an EventBus for your project you have to choose your **Gun**:
- Gun
The generic `Gun` which executes on the calling thread
- Sniper
Extension of a simple `Gun` which synchronizes each bullet shot
- Revolver
Extension of a simple `Gun` which can fire up to **6** bullets at once
- Uzi
Fully automatic `Gun` which uses kotlin coroutines for each bullet shot
Every Gun implementation inherits from the `Gun` class and iterates over all registered `targets`.
### Setup Target
```kotlin
import club.minnced.gunfire.core.Gun
import club.minnced.gunfire.core.impl.Sniper
import club.minnced.gunfire.core.target
val gun: Gun = Sniper()
fun main(args: Array) {
gun.target {
it.error.printStackTrace()
}
gun.target {
println(it.message)
}
}
```
> Note: Here we register a target that will print every **Throwable** that is caught by the Gun!
> Using the `Backfire` bullet specification!
### Fire Gun
```kotlin
import club.minnced.gunfire.core.Gun
import club.minnced.gunfire.core.impl.Sniper
import club.minnced.gunfire.core.fire
class LogBullet(val message: String)
fun logMessage(message: String) {
gun.fire {
LogBullet(message)
}
}
```
> Note: Here we fire a LogBullet which holds a message for the targets!
## Setup
JitPack Version: [  ](https://jitpack.io/#MinnDevelopment/Gunfire)
### Gradle
```gradle
respositories {
jcenter()
maven {
name 'jitpack.io'
url 'https://jitpack.io'
}
// ...
}
dependencies {
compile 'org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.1'
compile 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.14'
compile 'com.github.MinnDevelopment.Gunfire:core:master-SNAPSHOT'
compile 'com.github.MinnDevelopment.Gunfire:commons:master-SNAPSHOT'
// ...
}
```
### Maven
```xml
https://jitpack.io
com.github.MinnDevelopment.Gunfire
core
master-SNAPSHOT
com.github.MinnDevelopment.Gunfire
commons
master-SNAPSHOT
```
## Examples
There is a [Step-by-Step](https://github.com/MinnDevelopment/Gunfire/tree/master/Examples/Step%20by%20Step/src/main/kotlin) guide
and an example which uses bullets to print messages to the console in the [Examples Directories](https://github.com/MinnDevelopment/Gunfire/tree/master/Examples)!