Skip to content

Commit

Permalink
Bump version to 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
alialbaali committed Jan 26, 2021
1 parent cdfbb7d commit 167b517
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 19 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "io.kamel"
version = "0.0.3"
version = "0.0.4"

allprojects {
repositories {
Expand All @@ -30,7 +30,7 @@ publishing {
create<MavenPublication>("maven") {
groupId = "io.kamel"
artifactId = "kamel-core"
version = "0.0.3"
version = "0.0.4"

from(components["kotlin"])
}
Expand Down
19 changes: 10 additions & 9 deletions kamel-core/src/main/kotlin/io/kamel/core/LazyImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ public fun LazyImage(
) {
when (resource) {
is Resource.Loading -> if (onLoading != null) onLoading()
is Resource.Success -> Image(
resource.value,
contentDescription,
modifier,
alignment,
contentScale,
alpha,
colorFilter
)
is Resource.Success ->
Image(
resource.value,
contentDescription,
modifier,
alignment,
contentScale,
alpha,
colorFilter
)
is Resource.Failure -> if (onFailure != null) onFailure(resource.exception)
}
}
Expand Down
18 changes: 10 additions & 8 deletions kamel-core/src/main/kotlin/io/kamel/core/Resource.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.kamel.core

import io.kamel.core.Resource.*

/**
* A class represents an asynchronous resource loading.
*/
Expand Down Expand Up @@ -35,26 +37,26 @@ public sealed class Resource<out T> {
* Returns true if the resource still in the loading state, false otherwise.
*/
public val Resource<*>.isLoading: Boolean
get() = this is Resource.Loading
get() = this is Loading

/**
* Returns true if the resource represents a successful outcome, false otherwise.
*/
public val Resource<*>.isSuccess: Boolean
get() = this is Resource.Success
get() = this is Success

/**
* Returns true if the resource represents a failure outcome, false otherwise.
*/
public val Resource<*>.isFailure: Boolean
get() = this is Resource.Failure
get() = this is Failure

/**
* Returns [Resource.Success] with the [transform] function applied on the value if the resource represents success.
* or [Resource.Failure] with the original exception if the resource represents failure.
* Returns [Success] with the [transform] function applied on the value if the resource represents success.
* or [Failure] with the original exception if the resource represents failure.
*/
public inline fun <T, R> Resource<T>.map(transform: (T) -> R): Resource<R> = when (this) {
is Resource.Loading -> Resource.Loading
is Resource.Success -> Resource.Success(transform(value))
is Resource.Failure -> Resource.Failure(exception)
is Loading -> Loading
is Success -> Success(transform(value))
is Failure -> Failure(exception)
}

0 comments on commit 167b517

Please sign in to comment.