-
Notifications
You must be signed in to change notification settings - Fork 2
State management: Base viewModel #57
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
Conversation
amaury901130
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💪
example/app/src/main/java/com/rootstrap/androidcomposebase/ui/base/BaseViewModel.kt
Outdated
Show resolved
Hide resolved
hrodrick
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! Just left a comment
| .matches() || password.isEmpty() | ||
| updateUiState { it.copy(password = password, showPasswordError = !isPasswordValid) } | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably you can add a function here:
private fun validateInput(input: String, regex: Regex): Boolean {
return regex.matches(input) || input.isEmpty()
}
to avoid duplicating the validation checks, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation logic runs every time the user types, this could be inefficient if validating too frequently
You could debounce the validation to only run after the user stops typing or only validate when the onLogingButtonClicked is called.
wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll leave a todo
| import kotlinx.coroutines.flow.update | ||
| import kotlinx.coroutines.launch | ||
|
|
||
| open class BaseViewModel<UiStateType : UiState, NavigationEventT : Any>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this class could be abstract
Issue:
#19
closes #19
Description
Added base view model in the app and in the example app modules.
Added interface for uiState