diff --git a/reactiveviewmodel/build.gradle b/reactiveviewmodel/build.gradle index d933372..34d42bd 100644 --- a/reactiveviewmodel/build.gradle +++ b/reactiveviewmodel/build.gradle @@ -44,7 +44,7 @@ afterEvaluate { release(MavenPublication) { from components.release groupId = 'com.alexdeww.reactiveviewmodel' - version = '2.3.9' + version = '2.4.0' } } } diff --git a/reactiveviewmodel/src/main/java/com/alexdeww/reactiveviewmodel/core/property/ConfirmationEvent.kt b/reactiveviewmodel/src/main/java/com/alexdeww/reactiveviewmodel/core/property/ConfirmationEvent.kt index 46458ef..a05a53b 100644 --- a/reactiveviewmodel/src/main/java/com/alexdeww/reactiveviewmodel/core/property/ConfirmationEvent.kt +++ b/reactiveviewmodel/src/main/java/com/alexdeww/reactiveviewmodel/core/property/ConfirmationEvent.kt @@ -16,6 +16,9 @@ class ConfirmationEvent internal constructor(debounceInterval: Long? = private sealed class EventType { data class Pending(val data: Any) : EventType() object Confirmed : EventType() + + @Suppress("UNCHECKED_CAST") + fun tryGetData(): T? = if (this is Pending) data as T else null } private val eventState = State(EventType.Confirmed, debounceInterval) @@ -69,7 +72,7 @@ class ConfirmationEvent internal constructor(debounceInterval: Long? = @Suppress("UNCHECKED_CAST") override fun onActive() { super.onActive() - addSource(eventState.liveData) { value = (it as? EventType.Pending)?.data as T } + addSource(eventState.liveData) { value = it.tryGetData() } } override fun onInactive() {