for a basic need + Close to real-time + Emulation of bidirectional communication - Reopening connection is expensive - Still unnecessary requests to server - Still slow
LoadNextPageAction : Action() data class ErrorLoadingPageAction(val error: Throwable, val page: Int) : Action() data class PageLoadedAction(val itemsLoaded: List<GithubRepository>, val page: Int) : Action() data class StartLoadingNextPage(val page: Int) : Action() } StateMachine Actions
data class ErrorLoadingFirstPageState(val errorMessage: String) : State() data class ShowContentState(val items: List<GithubRepository>, val page: Int) : State() }
and the current state to calculate the new state. */ private fun reducer(state: State, action: Action): State { return when (action) { is StartLoadingNextPage -> State.LoadingFirstPageState is PageLoadedAction -> State.ShowContentState(items = action.items, page = action.page) is ErrorLoadingPageAction -> State.ErrorLoadingFirstPageState(action.error.localizedMessage) } }