Created
January 11, 2019 23:46
-
-
Save adam-arold/a86e96673af4de775083e8e2608c0f60 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EventBus { | |
private val subscriptions = | |
mutableMapOf<KClass<out Any>, (Any) -> Unit>() | |
inline fun <reified T : Event> subscribe( | |
noinline callback: (T) -> Unit) { | |
return subscribe( | |
klass = T::class, | |
callback = callback) | |
} | |
fun <T : Event> subscribe(klass: KClass<T>, | |
callback: (T) -> Unit) { | |
subscriptions[klass] = callback as (Any) -> Unit | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment