From e3e814c9eb50031ff1e0568f66f210894dd3c3ed Mon Sep 17 00:00:00 2001 From: Alex Sokol Date: Sat, 10 Jul 2021 13:07:38 +0300 Subject: [PATCH 1/4] Meaningful generics names in ResourceState Now the generics name in the ResourceState class is `TValue`, `TError` instead of `T`, `E`. It is important to have understandable generics names while `T` and `E` may be misinterpreted (e.g. `T` as Throwable). Generic names is kinda stuff that safe to refactor. --- .../kotlin/dev/icerock/moko/mvvm/ResourceState.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/ResourceState.kt b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/ResourceState.kt index a6a93278..9406deaa 100644 --- a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/ResourceState.kt +++ b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/ResourceState.kt @@ -4,18 +4,18 @@ package dev.icerock.moko.mvvm -sealed class ResourceState { - data class Success(val data: T) : ResourceState() - data class Failed(val error: E) : ResourceState() - class Loading : ResourceState() - class Empty : ResourceState() +sealed class ResourceState { + data class Success(val data: TData) : ResourceState() + data class Failed(val error: TError) : ResourceState() + class Loading : ResourceState() + class Empty : ResourceState() fun isLoading(): Boolean = this is Loading fun isSuccess(): Boolean = this is Success fun isEmpty(): Boolean = this is Empty fun isFailed(): Boolean = this is Failed - fun dataValue(): T? = (this as? Success)?.data + fun dataValue(): TData? = (this as? Success)?.data - fun errorValue(): E? = (this as? Failed)?.error + fun errorValue(): TError? = (this as? Failed)?.error } From 007bb4ce04226a6ef7f4078c7802068b0c786eeb Mon Sep 17 00:00:00 2001 From: Alex Sokol Date: Sat, 10 Jul 2021 13:11:12 +0300 Subject: [PATCH 2/4] Redundant generics removed in ResourceState Since in Kotlin Type System every Type extends Nothing, and ResourceState generics are covariant, it is possible to remove redundant generics and replace them with Nothing. All usages in library updated --- .../kotlin/dev/icerock/moko/mvvm/ResourceState.kt | 8 ++++---- .../kotlin/dev/icerock/moko/mvvm/StateExt.kt | 6 +++--- .../moko/mvvm/livedata/StateLiveDataConditions.kt | 8 ++++---- .../icerock/moko/mvvm/livedata/StateLiveDataExt.kt | 6 +++--- .../moko/mvvm/livedata/StateLiveDataMerges.kt | 6 +++--- .../moko/mvvm/livedata/StateLiveDataTransforms.kt | 12 ++++++------ 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/ResourceState.kt b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/ResourceState.kt index 9406deaa..11185d9b 100644 --- a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/ResourceState.kt +++ b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/ResourceState.kt @@ -5,10 +5,10 @@ package dev.icerock.moko.mvvm sealed class ResourceState { - data class Success(val data: TData) : ResourceState() - data class Failed(val error: TError) : ResourceState() - class Loading : ResourceState() - class Empty : ResourceState() + data class Success(val data: TData) : ResourceState() + data class Failed(val error: TError) : ResourceState() + object Loading : ResourceState() + object Empty : ResourceState() fun isLoading(): Boolean = this is Loading fun isSuccess(): Boolean = this is Success diff --git a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/StateExt.kt b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/StateExt.kt index 1aecbeca..3459af2b 100644 --- a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/StateExt.kt +++ b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/StateExt.kt @@ -11,7 +11,7 @@ fun T?.asState(whenNull: () -> ResourceState): ResourceState this?.asState() ?: whenNull() fun List.asState(): ResourceState, E> = if (this.isEmpty()) { - ResourceState.Empty() + ResourceState.Empty } else { ResourceState.Success(this) } @@ -20,7 +20,7 @@ fun List?.asState(whenNull: () -> ResourceState, E>): Resource this?.asState() ?: whenNull() inline fun ResourceState?.nullAsEmpty(): ResourceState = - this ?: ResourceState.Empty() + this ?: ResourceState.Empty inline fun ResourceState?.nullAsLoading(): ResourceState = - this ?: ResourceState.Loading() + this ?: ResourceState.Loading diff --git a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataConditions.kt b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataConditions.kt index 664d31e6..667a18c2 100644 --- a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataConditions.kt +++ b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataConditions.kt @@ -17,23 +17,23 @@ fun LiveData>.isEmptyState(): LiveData = map fun , LD : LiveData> List.isSuccessState(): LiveData = MediatorLiveData(false) .composition(this) { list -> - list.firstOrNull { it !is ResourceState.Success<*, *> } == null + list.firstOrNull { it !is ResourceState.Success<*> } == null } fun , LD : LiveData> List.isLoadingState(): LiveData = MediatorLiveData(false) .composition(this) { list -> - list.firstOrNull { it is ResourceState.Loading<*, *> } != null + list.firstOrNull { it is ResourceState.Loading } != null } fun , LD : LiveData> List.isErrorState(): LiveData = MediatorLiveData(false) .composition(this) { list -> - list.firstOrNull { it is ResourceState.Failed<*, *> } != null + list.firstOrNull { it is ResourceState.Failed<*> } != null } fun , LD : LiveData> List.isEmptyState(): LiveData = MediatorLiveData(false) .composition(this) { list -> - list.firstOrNull { it is ResourceState.Empty<*, *> } != null + list.firstOrNull { it is ResourceState.Empty } != null } diff --git a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataExt.kt b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataExt.kt index 5fc6162e..a43a8c31 100644 --- a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataExt.kt +++ b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataExt.kt @@ -14,12 +14,12 @@ fun LiveData>.error(): LiveData = map { it.errorV fun LiveData>.errorValue(): E? = value.errorValue() -fun , LD : LiveData> List.error(): LiveData = +fun , LD : LiveData> List.error(): LiveData = MediatorLiveData(null) .composition(this) { list -> @Suppress("UNCHECKED_CAST") val errorItem = list.firstOrNull { - (it is ResourceState.Failed<*, *>) - } as? ResourceState.Failed + (it is ResourceState.Failed<*>) + } as? ResourceState.Failed errorItem?.error } diff --git a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataMerges.kt b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataMerges.kt index c7c0c07a..21d06d40 100644 --- a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataMerges.kt +++ b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataMerges.kt @@ -12,17 +12,17 @@ fun LiveData>.concatData( ): LiveData> = mergeWith(liveData) { firstState, secondState -> val state: ResourceState = when { - (firstState is ResourceState.Loading || secondState is ResourceState.Loading) -> ResourceState.Loading() + (firstState is ResourceState.Loading || secondState is ResourceState.Loading) -> ResourceState.Loading (firstState is ResourceState.Failed) -> ResourceState.Failed(firstState.error) (secondState is ResourceState.Failed) -> ResourceState.Failed(secondState.error) - (firstState is ResourceState.Empty || secondState is ResourceState.Empty) -> ResourceState.Empty() + (firstState is ResourceState.Empty || secondState is ResourceState.Empty) -> ResourceState.Empty (firstState is ResourceState.Success && secondState is ResourceState.Success) -> ResourceState.Success( function( firstState.data, secondState.data ) ) - else -> ResourceState.Empty() + else -> ResourceState.Empty } state diff --git a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataTransforms.kt b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataTransforms.kt index 23ac05bf..aefcb64d 100644 --- a/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataTransforms.kt +++ b/mvvm-state/src/commonMain/kotlin/dev/icerock/moko/mvvm/livedata/StateLiveDataTransforms.kt @@ -11,8 +11,8 @@ fun LiveData>.dataTransform(transform: LiveData when (state) { is ResourceState.Success -> transform.invoke(MutableLiveData(state.data)) .map { ResourceState.Success(it) } - is ResourceState.Loading -> MutableLiveData(ResourceState.Loading()) - is ResourceState.Empty -> MutableLiveData(ResourceState.Empty()) + is ResourceState.Loading -> MutableLiveData(ResourceState.Loading) + is ResourceState.Empty -> MutableLiveData(ResourceState.Empty) is ResourceState.Failed -> MutableLiveData(ResourceState.Failed(state.error)) } } @@ -21,10 +21,10 @@ fun LiveData>.errorTransform(transform: LiveDat LiveData> = flatMap { state -> when (state) { is ResourceState.Success -> MutableLiveData(ResourceState.Success(state.data)) - is ResourceState.Loading -> MutableLiveData(ResourceState.Loading()) - is ResourceState.Empty -> MutableLiveData(ResourceState.Empty()) + is ResourceState.Loading -> MutableLiveData(ResourceState.Loading) + is ResourceState.Empty -> MutableLiveData(ResourceState.Empty) is ResourceState.Failed -> transform.invoke(MutableLiveData(state.error)) - .map { ResourceState.Failed(it) } + .map { ResourceState.Failed(it) } } } @@ -47,7 +47,7 @@ fun LiveData>.emptyAsData(dataBuilder: () -> T): fun LiveData>.emptyIf(emptyPredicate: (T) -> Boolean): LiveData> = map { when { - it is ResourceState.Success && emptyPredicate(it.data) -> ResourceState.Empty() + it is ResourceState.Success && emptyPredicate(it.data) -> ResourceState.Empty else -> it } } From 1f4798f92915e0e6b0b82c5608f3fa8390329a50 Mon Sep 17 00:00:00 2001 From: Alex Sokol Date: Sat, 10 Jul 2021 14:07:33 +0300 Subject: [PATCH 3/4] Updated ResourceState usages, which weren't updated in previous commit --- docs/mvvm-state/scripts/pages.js | 2 +- .../kotlin/dev/icerock/moko/mvvm/livedata/LiveDataTest.kt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/mvvm-state/scripts/pages.js b/docs/mvvm-state/scripts/pages.js index 527fdad1..4595987c 100644 --- a/docs/mvvm-state/scripts/pages.js +++ b/docs/mvvm-state/scripts/pages.js @@ -1 +1 @@ -var pages = [{"name":"sealed class ResourceState","description":"dev.icerock.moko.mvvm.ResourceState","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/index.html","searchKeys":["ResourceState","sealed class ResourceState"]},{"name":"class Empty : ResourceState ","description":"dev.icerock.moko.mvvm.ResourceState.Empty","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-empty/index.html","searchKeys":["Empty","class Empty : ResourceState "]},{"name":"fun Empty()","description":"dev.icerock.moko.mvvm.ResourceState.Empty.Empty","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-empty/-empty.html","searchKeys":["Empty","fun Empty()"]},{"name":"data class Failed(error: E) : ResourceState ","description":"dev.icerock.moko.mvvm.ResourceState.Failed","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/index.html","searchKeys":["Failed","data class Failed(error: E) : ResourceState "]},{"name":"fun Failed(error: E)","description":"dev.icerock.moko.mvvm.ResourceState.Failed.Failed","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/-failed.html","searchKeys":["Failed","fun Failed(error: E)"]},{"name":"operator fun component1(): E","description":"dev.icerock.moko.mvvm.ResourceState.Failed.component1","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/component1.html","searchKeys":["component1","operator fun component1(): E"]},{"name":"operator fun component1(): T","description":"dev.icerock.moko.mvvm.ResourceState.Success.component1","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/component1.html","searchKeys":["component1","operator fun component1(): T"]},{"name":"fun copy(error: E): ResourceState.Failed","description":"dev.icerock.moko.mvvm.ResourceState.Failed.copy","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/copy.html","searchKeys":["copy","fun copy(error: E): ResourceState.Failed"]},{"name":"fun copy(data: T): ResourceState.Success","description":"dev.icerock.moko.mvvm.ResourceState.Success.copy","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/copy.html","searchKeys":["copy","fun copy(data: T): ResourceState.Success"]},{"name":"val error: E","description":"dev.icerock.moko.mvvm.ResourceState.Failed.error","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/error.html","searchKeys":["error","val error: E"]},{"name":"class Loading : ResourceState ","description":"dev.icerock.moko.mvvm.ResourceState.Loading","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-loading/index.html","searchKeys":["Loading","class Loading : ResourceState "]},{"name":"fun Loading()","description":"dev.icerock.moko.mvvm.ResourceState.Loading.Loading","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-loading/-loading.html","searchKeys":["Loading","fun Loading()"]},{"name":"data class Success(data: T) : ResourceState ","description":"dev.icerock.moko.mvvm.ResourceState.Success","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/index.html","searchKeys":["Success","data class Success(data: T) : ResourceState "]},{"name":"fun Success(data: T)","description":"dev.icerock.moko.mvvm.ResourceState.Success.Success","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/-success.html","searchKeys":["Success","fun Success(data: T)"]},{"name":"val data: T","description":"dev.icerock.moko.mvvm.ResourceState.Success.data","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/data.html","searchKeys":["data","val data: T"]},{"name":"fun LiveData>.data(): LiveData","description":"dev.icerock.moko.mvvm.livedata.data","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/data.html","searchKeys":["data","fun LiveData>.data(): LiveData"]},{"name":"fun dataValue(): T?","description":"dev.icerock.moko.mvvm.ResourceState.dataValue","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/data-value.html","searchKeys":["dataValue","fun dataValue(): T?"]},{"name":"fun LiveData>.dataValue(): T?","description":"dev.icerock.moko.mvvm.livedata.dataValue","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/data-value.html","searchKeys":["dataValue","fun LiveData>.dataValue(): T?"]},{"name":"fun errorValue(): E?","description":"dev.icerock.moko.mvvm.ResourceState.errorValue","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/error-value.html","searchKeys":["errorValue","fun errorValue(): E?"]},{"name":"fun LiveData>.errorValue(): E?","description":"dev.icerock.moko.mvvm.livedata.errorValue","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/error-value.html","searchKeys":["errorValue","fun LiveData>.errorValue(): E?"]},{"name":"fun isEmpty(): Boolean","description":"dev.icerock.moko.mvvm.ResourceState.isEmpty","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/is-empty.html","searchKeys":["isEmpty","fun isEmpty(): Boolean"]},{"name":"fun isFailed(): Boolean","description":"dev.icerock.moko.mvvm.ResourceState.isFailed","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/is-failed.html","searchKeys":["isFailed","fun isFailed(): Boolean"]},{"name":"fun isLoading(): Boolean","description":"dev.icerock.moko.mvvm.ResourceState.isLoading","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/is-loading.html","searchKeys":["isLoading","fun isLoading(): Boolean"]},{"name":"fun isSuccess(): Boolean","description":"dev.icerock.moko.mvvm.ResourceState.isSuccess","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/is-success.html","searchKeys":["isSuccess","fun isSuccess(): Boolean"]},{"name":"fun LiveData>.concatData(liveData: LiveData>, function: (T1, T2) -> OT): LiveData>","description":"dev.icerock.moko.mvvm.livedata.concatData","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/concat-data.html","searchKeys":["concatData","fun LiveData>.concatData(liveData: LiveData>, function: (T1, T2) -> OT): LiveData>"]},{"name":"fun LiveData>.dataTransform(transform: LiveData.() -> LiveData): LiveData>","description":"dev.icerock.moko.mvvm.livedata.dataTransform","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/data-transform.html","searchKeys":["dataTransform","fun LiveData>.dataTransform(transform: LiveData.() -> LiveData): LiveData>"]},{"name":"fun LiveData>.emptyAsData(dataBuilder: () -> T): LiveData>","description":"dev.icerock.moko.mvvm.livedata.emptyAsData","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/empty-as-data.html","searchKeys":["emptyAsData","fun LiveData>.emptyAsData(dataBuilder: () -> T): LiveData>"]},{"name":"fun LiveData>.emptyAsError(errorBuilder: () -> E): LiveData>","description":"dev.icerock.moko.mvvm.livedata.emptyAsError","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/empty-as-error.html","searchKeys":["emptyAsError","fun LiveData>.emptyAsError(errorBuilder: () -> E): LiveData>"]},{"name":"fun LiveData>.emptyIf(emptyPredicate: (T) -> Boolean): LiveData>","description":"dev.icerock.moko.mvvm.livedata.emptyIf","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/empty-if.html","searchKeys":["emptyIf","fun LiveData>.emptyIf(emptyPredicate: (T) -> Boolean): LiveData>"]},{"name":"fun LiveData>.errorTransform(transform: LiveData.() -> LiveData): LiveData>","description":"dev.icerock.moko.mvvm.livedata.errorTransform","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/error-transform.html","searchKeys":["errorTransform","fun LiveData>.errorTransform(transform: LiveData.() -> LiveData): LiveData>"]},{"name":"inline fun ResourceState?.nullAsEmpty(): ResourceState","description":"dev.icerock.moko.mvvm.nullAsEmpty","location":"mvvm-state/dev.icerock.moko.mvvm/null-as-empty.html","searchKeys":["nullAsEmpty","inline fun ResourceState?.nullAsEmpty(): ResourceState"]},{"name":"inline fun ResourceState?.nullAsLoading(): ResourceState","description":"dev.icerock.moko.mvvm.nullAsLoading","location":"mvvm-state/dev.icerock.moko.mvvm/null-as-loading.html","searchKeys":["nullAsLoading","inline fun ResourceState?.nullAsLoading(): ResourceState"]}] +var pages = [{"name":"sealed class ResourceState","description":"dev.icerock.moko.mvvm.ResourceState","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/index.html","searchKeys":["ResourceState","sealed class ResourceState"]},{"name":"class Empty : ResourceState ","description":"dev.icerock.moko.mvvm.ResourceState.Empty","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-empty/index.html","searchKeys":["Empty","class Empty : ResourceState "]},{"name":"fun Empty()","description":"dev.icerock.moko.mvvm.ResourceState.Empty.Empty","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-empty/-empty.html","searchKeys":["Empty","fun Empty()"]},{"name":"data class Failed(error: E) : ResourceState ","description":"dev.icerock.moko.mvvm.ResourceState.Failed","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/index.html","searchKeys":["Failed","data class Failed(error: E) : ResourceState "]},{"name":"fun Failed(error: E)","description":"dev.icerock.moko.mvvm.ResourceState.Failed.Failed","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/-failed.html","searchKeys":["Failed","fun Failed(error: E)"]},{"name":"operator fun component1(): E","description":"dev.icerock.moko.mvvm.ResourceState.Failed.component1","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/component1.html","searchKeys":["component1","operator fun component1(): E"]},{"name":"operator fun component1(): T","description":"dev.icerock.moko.mvvm.ResourceState.Success.component1","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/component1.html","searchKeys":["component1","operator fun component1(): T"]},{"name":"fun copy(error: E): ResourceState.Failed","description":"dev.icerock.moko.mvvm.ResourceState.Failed.copy","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/copy.html","searchKeys":["copy","fun copy(error: E): ResourceState.Failed"]},{"name":"fun copy(data: T): ResourceState.Success","description":"dev.icerock.moko.mvvm.ResourceState.Success.copy","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/copy.html","searchKeys":["copy","fun copy(data: T): ResourceState.Success"]},{"name":"val error: E","description":"dev.icerock.moko.mvvm.ResourceState.Failed.error","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-failed/error.html","searchKeys":["error","val error: E"]},{"name":"class Loading : ResourceState ","description":"dev.icerock.moko.mvvm.ResourceState.Loading","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-loading/index.html","searchKeys":["Loading","class Loading : ResourceState "]},{"name":"fun Loading()","description":"dev.icerock.moko.mvvm.ResourceState.Loading.Loading","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-loading/-loading.html","searchKeys":["Loading","fun Loading()"]},{"name":"data class Success(data: T) : ResourceState ","description":"dev.icerock.moko.mvvm.ResourceState.Success","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/index.html","searchKeys":["Success","data class Success(data: T) : ResourceState "]},{"name":"fun Success(data: T)","description":"dev.icerock.moko.mvvm.ResourceState.Success.Success","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/-success.html","searchKeys":["Success","fun Success(data: T)"]},{"name":"val data: T","description":"dev.icerock.moko.mvvm.ResourceState.Success.data","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/-success/data.html","searchKeys":["data","val data: T"]},{"name":"fun LiveData>.data(): LiveData","description":"dev.icerock.moko.mvvm.livedata.data","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/data.html","searchKeys":["data","fun LiveData>.data(): LiveData"]},{"name":"fun dataValue(): T?","description":"dev.icerock.moko.mvvm.ResourceState.dataValue","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/data-value.html","searchKeys":["dataValue","fun dataValue(): T?"]},{"name":"fun LiveData>.dataValue(): T?","description":"dev.icerock.moko.mvvm.livedata.dataValue","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/data-value.html","searchKeys":["dataValue","fun LiveData>.dataValue(): T?"]},{"name":"fun errorValue(): E?","description":"dev.icerock.moko.mvvm.ResourceState.errorValue","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/error-value.html","searchKeys":["errorValue","fun errorValue(): E?"]},{"name":"fun LiveData>.errorValue(): E?","description":"dev.icerock.moko.mvvm.livedata.errorValue","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/error-value.html","searchKeys":["errorValue","fun LiveData>.errorValue(): E?"]},{"name":"fun isEmpty(): Boolean","description":"dev.icerock.moko.mvvm.ResourceState.isEmpty","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/is-empty.html","searchKeys":["isEmpty","fun isEmpty(): Boolean"]},{"name":"fun isFailed(): Boolean","description":"dev.icerock.moko.mvvm.ResourceState.isFailed","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/is-failed.html","searchKeys":["isFailed","fun isFailed(): Boolean"]},{"name":"fun isLoading(): Boolean","description":"dev.icerock.moko.mvvm.ResourceState.isLoading","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/is-loading.html","searchKeys":["isLoading","fun isLoading(): Boolean"]},{"name":"fun isSuccess(): Boolean","description":"dev.icerock.moko.mvvm.ResourceState.isSuccess","location":"mvvm-state/dev.icerock.moko.mvvm/-resource-state/is-success.html","searchKeys":["isSuccess","fun isSuccess(): Boolean"]},{"name":"fun LiveData>.concatData(liveData: LiveData>, function: (T1, T2) -> OT): LiveData>","description":"dev.icerock.moko.mvvm.livedata.concatData","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/concat-data.html","searchKeys":["concatData","fun LiveData>.concatData(liveData: LiveData>, function: (T1, T2) -> OT): LiveData>"]},{"name":"fun LiveData>.dataTransform(transform: LiveData.() -> LiveData): LiveData>","description":"dev.icerock.moko.mvvm.livedata.dataTransform","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/data-transform.html","searchKeys":["dataTransform","fun LiveData>.dataTransform(transform: LiveData.() -> LiveData): LiveData>"]},{"name":"fun LiveData>.emptyAsData(dataBuilder: () -> T): LiveData>","description":"dev.icerock.moko.mvvm.livedata.emptyAsData","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/empty-as-data.html","searchKeys":["emptyAsData","fun LiveData>.emptyAsData(dataBuilder: () -> T): LiveData>"]},{"name":"fun LiveData>.emptyAsError(errorBuilder: () -> E): LiveData>","description":"dev.icerock.moko.mvvm.livedata.emptyAsError","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/empty-as-error.html","searchKeys":["emptyAsError","fun LiveData>.emptyAsError(errorBuilder: () -> E): LiveData>"]},{"name":"fun LiveData>.emptyIf(emptyPredicate: (T) -> Boolean): LiveData>","description":"dev.icerock.moko.mvvm.livedata.emptyIf","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/empty-if.html","searchKeys":["emptyIf","fun LiveData>.emptyIf(emptyPredicate: (T) -> Boolean): LiveData>"]},{"name":"fun LiveData>.errorTransform(transform: LiveData.() -> LiveData): LiveData>","description":"dev.icerock.moko.mvvm.livedata.errorTransform","location":"mvvm-state/dev.icerock.moko.mvvm.livedata/error-transform.html","searchKeys":["errorTransform","fun LiveData>.errorTransform(transform: LiveData.() -> LiveData): LiveData>"]},{"name":"inline fun ResourceState?.nullAsEmpty(): ResourceState","description":"dev.icerock.moko.mvvm.nullAsEmpty","location":"mvvm-state/dev.icerock.moko.mvvm/null-as-empty.html","searchKeys":["nullAsEmpty","inline fun ResourceState?.nullAsEmpty(): ResourceState"]},{"name":"inline fun ResourceState?.nullAsLoading(): ResourceState","description":"dev.icerock.moko.mvvm.nullAsLoading","location":"mvvm-state/dev.icerock.moko.mvvm/null-as-loading.html","searchKeys":["nullAsLoading","inline fun ResourceState?.nullAsLoading(): ResourceState"]}] diff --git a/mvvm-state/src/commonTest/kotlin/dev/icerock/moko/mvvm/livedata/LiveDataTest.kt b/mvvm-state/src/commonTest/kotlin/dev/icerock/moko/mvvm/livedata/LiveDataTest.kt index 3a2f6061..dcb22101 100644 --- a/mvvm-state/src/commonTest/kotlin/dev/icerock/moko/mvvm/livedata/LiveDataTest.kt +++ b/mvvm-state/src/commonTest/kotlin/dev/icerock/moko/mvvm/livedata/LiveDataTest.kt @@ -61,7 +61,7 @@ class LiveDataTest { @Test fun `dataTransform + mergeWith test`() { val vmIsAuthorized = MutableLiveData(true) - val state: MutableLiveData> = MutableLiveData(ResourceState.Empty()) + val state: MutableLiveData> = MutableLiveData(ResourceState.Empty) val isLoading: MutableLiveData = MutableLiveData(false) var dataTransformCounter = 0 @@ -91,7 +91,7 @@ class LiveDataTest { assertEquals(actual = mergeWithIsAuthorizedCounter, expected = 3) assertTrue { result.value.isEmpty() } - state.value = ResourceState.Loading() + state.value = ResourceState.Loading assertEquals(actual = dataTransformCounter, expected = 0) assertEquals(actual = mergeWithDataTransformCounter, expected = 0) From f5f7f5fe64297ca3dccdc261535cb5ae22e7fe0e Mon Sep 17 00:00:00 2001 From: Alex Sokol Date: Sat, 10 Jul 2021 14:32:18 +0300 Subject: [PATCH 4/4] :apiDump run and :check succeed --- mvvm-state/api/mvvm-state.api | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mvvm-state/api/mvvm-state.api b/mvvm-state/api/mvvm-state.api index 8319bca9..c3748e43 100644 --- a/mvvm-state/api/mvvm-state.api +++ b/mvvm-state/api/mvvm-state.api @@ -8,7 +8,7 @@ public abstract class dev/icerock/moko/mvvm/ResourceState { } public final class dev/icerock/moko/mvvm/ResourceState$Empty : dev/icerock/moko/mvvm/ResourceState { - public fun ()V + public static final field INSTANCE Ldev/icerock/moko/mvvm/ResourceState$Empty; } public final class dev/icerock/moko/mvvm/ResourceState$Failed : dev/icerock/moko/mvvm/ResourceState { @@ -23,7 +23,7 @@ public final class dev/icerock/moko/mvvm/ResourceState$Failed : dev/icerock/moko } public final class dev/icerock/moko/mvvm/ResourceState$Loading : dev/icerock/moko/mvvm/ResourceState { - public fun ()V + public static final field INSTANCE Ldev/icerock/moko/mvvm/ResourceState$Loading; } public final class dev/icerock/moko/mvvm/ResourceState$Success : dev/icerock/moko/mvvm/ResourceState {