Skip to content

Commit 0c95dd1

Browse files
author
Alex
committed
fix type cast for ConfirmationEvent
1 parent 2653d21 commit 0c95dd1

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

reactiveviewmodel/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ afterEvaluate {
4444
release(MavenPublication) {
4545
from components.release
4646
groupId = 'com.alexdeww.reactiveviewmodel'
47-
version = '2.3.9'
47+
version = '2.4.0'
4848
}
4949
}
5050
}

reactiveviewmodel/src/main/java/com/alexdeww/reactiveviewmodel/core/property/ConfirmationEvent.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ class ConfirmationEvent<T : Any> internal constructor(debounceInterval: Long? =
1616
private sealed class EventType {
1717
data class Pending(val data: Any) : EventType()
1818
object Confirmed : EventType()
19+
20+
@Suppress("UNCHECKED_CAST")
21+
fun <T> tryGetData(): T? = if (this is Pending) data as T else null
1922
}
2023

2124
private val eventState = State<EventType>(EventType.Confirmed, debounceInterval)
@@ -69,7 +72,7 @@ class ConfirmationEvent<T : Any> internal constructor(debounceInterval: Long? =
6972
@Suppress("UNCHECKED_CAST")
7073
override fun onActive() {
7174
super.onActive()
72-
addSource(eventState.liveData) { value = (it as? EventType.Pending)?.data as T }
75+
addSource(eventState.liveData) { value = it.tryGetData<T>() }
7376
}
7477

7578
override fun onInactive() {

0 commit comments

Comments
 (0)