2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-09 19:10:42 +00:00

Fixes #1187 - account for enum value change

This commit is contained in:
Jeff Boek 2019-03-26 09:13:59 -07:00
parent edb197d10b
commit cf0d1355b5

View File

@ -16,9 +16,15 @@ private class EventWrapper<T : Enum<T>>(
private val event: EventMetricType<T>,
private val keyMapper: ((String) -> T)? = null
) {
private val String.asCamelCase: String
get() = this.split("_").reduceIndexed { index, acc, s ->
if (index == 0) acc + s
else acc + s.capitalize()
}
fun track(event: Event) {
val extras = if (keyMapper != null) {
event.extras?.mapKeys { keyMapper.invoke(it.key) }
event.extras?.mapKeys { keyMapper.invoke(it.key.asCamelCase) }
} else {
null
}