Last active
April 3, 2018 03:03
-
-
Save Laimiux/d245847f4aac0581e5af6546b4d9ff2d 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 CommentFormModel(val commentService: CommentService) { | |
fun formState( | |
textChangedEvents: Observable<TextChangedEvent>, | |
submitEvents: Observable<SubmitCommentEvent> | |
) : Observable<CommentFormData> { | |
// Explicitly declaring the type, for clarity sake | |
val requestStateEvents: Observable<Lce<Comment>> = submitEvents | |
.switchMap { event -> commentService.submit(event.comment) } | |
// To use RxJava scan operator, we need to | |
// merge requestStateEvents and textChangedEvents | |
val events: Observable<Any> = Observable.merge(textChangedEvents, requestStateEvents) | |
// As you can see, we have a problem. The stream data type becomes Any | |
return ... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment