Skip to content

Latest commit

History

History
53 lines (43 loc) 路 1.69 KB

README.md

File metadata and controls

53 lines (43 loc) 路 1.69 KB

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.