Hi, is there a way to un-obfuscate an inner functi...
# javascript
a
Hi, is there a way to un-obfuscate an inner function in Kotlin/JS ? Like I have two a JS library that lets me execute one time per framerate a lambda, with
ticker.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
Copy 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 problem
r
Have you tried something like this?
Copy code
val lambda: (KeyboardEvent) -> Unit = { test(it) }
onPress {
    ticker.add(lambda)
}
onRelease {
    ticker.remove(lambda)
}
1
a
Mh still not
e
what you wrote is like
Copy code
ticker.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"
what to do about it, depends but if
ticker
is not Kotlin this will be tricky
a
I thinked a bit and I think that the way I'm doing this is not possible, as the two
onPress/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 this
Thanks for the help through !