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

MBL-1077: Coroutines in ChangePasswordViewModel + Tests #1923

Merged
merged 7 commits into from
Jan 10, 2024

Conversation

Arkariang
Copy link
Contributor

@Arkariang Arkariang commented Jan 8, 2024

📲 What

Adding coroutines flow in detail document with technical clarifications available here

  • using StateFlow to be consumed on compose code (ChangePasswordActivity)
  • using collectAsStateWithLifecycle when consuming vm's flows
  • instead of creating new networking layer methods/client, using .asFlow() from kotlinx.coroutines.rx2
  • using onStart, map, catch, and collect, it would be a similar usage to RXJava2 doOnSubscribe, map, doOnError, subscribe
    Test file migrated to adapt to the coroutines usage
  • producing UIStates uiState: StateFlow<UpdatePasswordUIState>

🤔 Why

  • No RXJava usage on UI or VM's any longer on new screens 🤞

👀 See

  • No user facing changes
    | | |

📋 QA

  • Change your password

Story 📖

MBL-1077

mtgriego
mtgriego previously approved these changes Jan 8, 2024
Copy link
Contributor

@mtgriego mtgriego left a comment

Choose a reason for hiding this comment

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

Looking great! Lets do it everywhere!

app/build.gradle Outdated Show resolved Hide resolved
class ChangePasswordViewModelFactory(private val environment: Environment) :
ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
return ChangePasswordViewModel(environment) as T
Copy link
Contributor

Choose a reason for hiding this comment

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

Just seeing a class go down ~100 lines while maintaining functionality really excites me for coroutines and the UI state model

Copy link
Contributor

Choose a reason for hiding this comment

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

especially since this is a smaller use case


fun updatePassword(oldPassword: String, newPassword: String) {
viewModelScope.launch {
// TODO: Avoid using GraphQL generated types such as UpdateUserPasswordMutation.Data, return data model defined within the app.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to propose a alternative to this as part of this migration effort? It would probably mean adding transformers/UiModels to the effort.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, seems a small effort, what do you think @leighdouglas and @ycheng-kickstarter ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take care of this one in a following PR

@codecov-commenter
Copy link

codecov-commenter commented Jan 9, 2024

Codecov Report

Attention: 5 lines in your changes are missing coverage. Please review.

Comparison is base (69c7220) 74.25% compared to head (40911fa) 74.26%.

Files Patch % Lines
.../kickstarter/viewmodels/ChangePasswordViewModel.kt 83.33% 2 Missing and 3 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #1923      +/-   ##
============================================
+ Coverage     74.25%   74.26%   +0.01%     
- Complexity     1963     1964       +1     
============================================
  Files           336      336              
  Lines         19653    19614      -39     
  Branches       2718     2711       -7     
============================================
- Hits          14593    14567      -26     
+ Misses         3490     3478      -12     
+ Partials       1570     1569       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Arkariang Arkariang merged commit 8045fef into master Jan 10, 2024
3 checks passed
@Arkariang Arkariang deleted the imartin/MBL-1077-uistatearchitecture branch January 10, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants