Event
abstract class Event<Data, E : Event<Data, E, O>, O : Event.Observer<Data, E>>(val name: String)(source)
Base abstraction for creating enum like event/observer type hierarchies using kotlin sealed classes & data objects.
e.g.
public sealed class MyEvent private constructor(
name: String,
): Event(name) {
public data object THIS: MyEvent("THIS")
public data object THAT: MyEvent("THAT")
public open class Observer(
event: MyEvent,
tag: String?,
executor: OnEvent.Executor?,
onEvent: OnEvent,
): Event.Observer(
event,
tag,
executor,
onEvent
)
public companion object: Entries(numEvents = 2) {
@JvmStatic
@Throws(IllegalArgumentException::class)
public override fun valueOf(name: String): MyEvent {
return super.valueOf(name)
}
@JvmStatic
public override fun valueOfOrNull(name: String): MyEvent? {
return super.valueOfOrNull(name)
}
@JvmStatic
public override fun entries(): Set {
return super.entries()
}
protected override val lazyEntries: ThisBlock> =
ThisBlock {
// NOTE: Update numEvents when adding an event
add(THIS); add(THAT);
}
}
protected final override fun createProtected(
event: MyEvent,
tag: String?,
executor: OnEvent.Executor?,
onEvent: OnEvent,
): Observer = Observer(event, tag, executor, onEvent)
}
Content copied to clipboard
See also
io.matthewnelson.kmp.tor.runtime.RuntimeEvent
Inheritors
Functions
Link copied to clipboard
protected abstract fun createProtected(event: E, tag: String?, executor: OnEvent.Executor?, onEvent: OnEvent<Data>): O
Protected factory function for creating instances of the Event.Observer implementation.
Link copied to clipboard
Creates a new observer for subscribing to its events.
Creates a new observer with the provided tag for subscribing to its events.