Created
March 27, 2018 05:53
-
-
Save Laimiux/fd99a009b5645877afb6553af91b4d37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CommentFormViewModel { | |
// Let's create a view state from the data provided. | |
fun createViewState( | |
data: CommentFormData, | |
onTextChanged: (TextChangedEvent) -> Unit, | |
onSubmitSelected: (SubmitCommentEvent) -> Unit | |
): CommentFormViewState{ | |
val isSubmitting = data.submitRequest?.let { it.isLoading} ?: false | |
return CommentFormViewState( | |
textEntered = data.comment, | |
isSubmitButtonEnabled = data.isCommentIsValid && !isSubmitting, | |
onTextEntered = { text -> | |
onTextChanged(TextChangedEvent(text)) | |
}, | |
onSubmitClicked = { | |
// We assume that view will disable submit button when | |
// isSubmitButtonEnabled = false | |
onSubmitClicked(SubmitCommentEvent(data.comment)) | |
} | |
)} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment