Event Characteristics
Imported from Github: https://github.com/koresframework/EventSys/issues/10
This is set to 1.9 milestone, but does not mean that will be delivered in 1.9 version, this is only a wip proposal.
## Proposal
Support a sort of `characteristics` in events (or `dynamic characteristics`).
## Example
Event:
```kotlin
interface AccountMoneyChangeEvent : Event {
val amount: Int
}
```
Characteristic inclusion:
```kotlin
val accountMoneyChangeEvent = factory.accountMoneyChangeEvent(-5).characteristic(Bank.OPERATION, Operation.WITHDRAW)
```
Or via factory:
```kotlin
interface AccountEventFactory {
@Characteristic(key = Operation::class, valueHandler = OperationHandler::class)
fun accountMoneyChangeEvent(amount: Int): AccountMoneyChangeEvent
}
object Operation : CharacteristicKey {
val WITHDRAW = OperationWithdraw
}
object OperationHandler : FactoryCharacteristicValueHandler {
override fun handleFactory(event: Event, factory: FactoryConfiguration): CharacteristicValue {
val operationCharacteristic = ...
return operationCharacteristic
}
}
```
## Motivation
This would allow custom dispatches for characteristic specific listeners, which could be channel based and characteristic based instead of channel based only.
The main difference between _Characteristics_ and [Extension Additional Properties](https://github.com/koresframework/EventSys#extension) is that _Characteristics_ are dynamic and does not require custom factory and custom class definitions, they could be set on the fly. And are easier to define.
Characteristic idea is to be something not bound to a specific group of events, but to an open group of events that may not correlate between them.
issue