Skip to content

🎤 Experimental event handling for Java/Kotlin.

License

Notifications You must be signed in to change notification settings

ImXico/Reporter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reporter 🎤

Build Status kotlin license

Tiny and lightweight event handling system for Java/Kotlin. It's an annotation-based implementation of the observer pattern that takes away all the boilerplate that usually comes with it, making it super easy to use.

⚠️ Note: This was purely experimental, and thus is not fully fledged nor maintained.

Events

Have all events implementing the Event interface.

class PersonOnlineEvent(val name: String) : Event

Subscribers

Every class that wants to subscribe to one or more Event must implement the Subscriber interface.

class Bob : Subscriber
class Joe : Subscriber

Subscriptions

Every method that is listening to events should be marked with the @Subscription annotation.

Those methods should only have one parameter, and that parameter should be an implementation of an Event.

class Bob : Subscriber {

  @Subscription
  fun greet(event: PersonOnlineEvent) = println("Bob says: Hi, ${event.name}!")
}
class Joe : Subscriber {
  
  @Subscription
  fun greet(event: PersonOnlineEvent) = println("Joe says: Hey ${event.name}.")
}

Sample Usage

val bob: Bob = Bob()
val joe: Joe = Joe()
Reporter.registerAll(bob, joe)
Reporter.report(PersonOnlineEvent(name = "Jon"))
Bob says: Hi, Jon!
Joe says: Hey Jon.