Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work on generics in ResourceState #152

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

y9san9
Copy link
Collaborator

@y9san9 y9san9 commented Jul 10, 2021

Generics now are more meaningful, and redundant generics were removed

y9san9 added 2 commits July 10, 2021 13:07
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.
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
@y9san9
Copy link
Collaborator Author

y9san9 commented Jul 10, 2021

@Alex009 I did

@y9san9 y9san9 marked this pull request as draft July 10, 2021 10:59
@y9san9 y9san9 marked this pull request as ready for review July 10, 2021 11:32
@sonarcloud
Copy link

sonarcloud bot commented Jul 10, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Comment on lines +8 to +11
data class Success<out TData>(val data: TData) : ResourceState<TData, Nothing>()
data class Failed<out TError>(val error: TError) : ResourceState<Nothing, TError>()
object Loading : ResourceState<Nothing, Nothing>()
object Empty : ResourceState<Nothing, Nothing>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in common:

class Test {
    val myData: ResourceState<Int, String> = ResourceState.Success(10)
}

try on swift:

func test() {
    let test = Test()
    let data = test.myData as? ResourceStateSuccess<Int>
    let data2: ResourceStateSuccess<Int> = test.myData.asSuccess()
}

@@ -11,7 +11,7 @@ fun <T, E> T?.asState(whenNull: () -> ResourceState<T, E>): ResourceState<T, E>
this?.asState() ?: whenNull()

fun <T, E> List<T>.asState(): ResourceState<List<T>, E> = if (this.isEmpty()) {
ResourceState.Empty()
ResourceState.Empty
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should also add into release notes guide to migration. please add migration regexp to pr description, we will add it into release notes later

data class Failed<out T, out E>(val error: E) : ResourceState<T, E>()
class Loading<out T, out E> : ResourceState<T, E>()
class Empty<out T, out E> : ResourceState<T, E>()
sealed class ResourceState<out TData, out TError> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change should support simple automatically migration if we want to merge it...try to write some regexp which will allow us and others migrate to new version in minutes on any size of project codebase

@Alex009 Alex009 added this to the 0.12.0 milestone Feb 11, 2022
@Alex009 Alex009 modified the milestones: 0.12.0, 0.13.0 Feb 25, 2022
@Alex009 Alex009 modified the milestones: 0.13.0, 0.14.0 Apr 30, 2022
@Alex009 Alex009 modified the milestones: 0.14.0, 0.15.0 Sep 13, 2022
@Alex009 Alex009 modified the milestones: 0.15.0, 0.16.0 Dec 19, 2022
@Alex009 Alex009 modified the milestones: 0.16.0, 0.17.0 Apr 8, 2023
@Alex009 Alex009 self-requested a review August 14, 2024 02:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants