-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataState.kt
25 lines (18 loc) · 948 Bytes
/
DataState.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.anikinkirill.mviplayground.util
data class DataState<T>(
var error: Event<StateError>? = null, // Event and StateError from StateResource helper class
var loading: Loading = Loading(false), // Loading from StateResource helper class
var data: Data<T>? = null // Data from StateResource helper class
) {
companion object {
fun <T> error(response: Response) : DataState<T> {
return DataState(error = Event(StateError(response)))
}
fun <T> loading(isLoading: Boolean, cachedData: T? = null) : DataState<T> {
return DataState(null, Loading(isLoading), Data(Event.dataEvent(cachedData), null))
}
fun <T> data(data: T? = null, response: Response? = null) : DataState<T> {
return DataState(null, Loading(false), Data(Event.dataEvent(data), Event.responseEvent(response)))
}
}
}