Slide 63
Slide 63 text
@pacoworks
Our business logic function
static void subscribePagination(
PaginationState state,
Observable endOfPage,
Function>> service) {
// Chain with switchMap
doSM(
// For every new state
() -> state.elements,
// Wait for the end of the page
elements -> endOfPage.first(),
// Get latest page
elements, click -> state.pages.first(),
// Request and append new page
elements, click, page ->
service.apply(page)
.map { elements.plus(it) }
.doOnNext { state.pages.call(page + 1) }
) // Reapply state
.subscribe(state.elements)
}
Coupled only with
functions,
observables and data
Single
responsibility
No leaky direct
interaction with UI
No UI thread
required
63