<@U7BB83NPR> I didn't quite get what you wanted to...
# tornadofx
e
@Carlton Whitehead I didn't quite get what you wanted to do with method references / EventBus. Can you give me an example?
c
init { subscribe(this::onEvent) } fun onEvent(event: MyEvent) { // a bit too complex body to leave in the init // easier entry point for unit testing }
e
@Carlton Whitehead
subscribe<MyEvent> { onEvent(it) }
c
That'll do, thanks!
e
The reason you can't pass it as a function reference is that the function parameter operates on an EventContext. You're losing access to that context by doing this.
So if you need the context, you can pass that as well.
subscribe<MyEvent> { onEvent(this, it) }
That would imply
fun onEvent(context: EventContext, event: MyEvent) {}
Function references cannot describe this function call, so you have to call the function explicity.
c
Ahh, I figured I must be missing something important there
Thanks
e
Hehe 🙂 Yeah, the function signature gives it away. Function references only work with a single parameter.
You're welcome 🙂