Ayfri
02/25/2022, 6:20 PMticker.add { code }
, but to remove it I have to have the same lambda, ticker.remove { code }
, but in Kotlin is just doesn't work as a JS function is generated for both but has a different name, so it just doesn't work
My code
fun onKeep(callback: (KeyboardEvent) -> Unit) {
fun test(keyboardEvent: KeyboardEvent) {
if (enabled) callback(keyboardEvent)
}
onPress {
ticker.add { test(it) } // correctly add the function
}
onRelease {
ticker.remove { test(it) } // can't remove function as JS result is not the same
}
}
But this very code works if translated to JS and directly run in JS, so it's a Kotlin problemRobert Jaros
02/25/2022, 6:41 PMval lambda: (KeyboardEvent) -> Unit = { test(it) }
onPress {
ticker.add(lambda)
}
onRelease {
ticker.remove(lambda)
}
Ayfri
02/25/2022, 7:48 PMephemient
02/25/2022, 9:32 PMticker.add((it) => test(it));
ticker.remove((it) => test(it));
in Javascript, which also doesn't work. I'm not sure what you mean by "works if translated to JS"ephemient
02/25/2022, 9:35 PMticker
is not Kotlin this will be trickyAyfri
02/25/2022, 10:02 PMonPress/onRelease
events won't have the same values for their lambda parameter, it's a KeyboardEvent
but the values won't be the same, I'll try another way to code thisAyfri
02/25/2022, 10:02 PM