-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComponentState.kt
22 lines (18 loc) · 881 Bytes
/
ComponentState.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
package com.mctech.library.architecture
/**
* Used to manage separated component lifecycle. For example, let's say we have 3 different components on your screen.
* Each component should load some individual data and show on the screen.
*
* So basically, you can start three coroutine loading data flow and update each livedata with this component.
* And according the requests return some data or error you just update this component that your screen component will be notified with the changes and so on.
*
*/
sealed class ComponentState<out T> {
object Initializing : ComponentState<Nothing>()
sealed class Loading : ComponentState<Nothing>(){
object FromEmpty : Loading()
object FromData : Loading()
}
data class Error(val reason: Throwable) : ComponentState<Nothing>()
data class Success<T>(val result: T) : ComponentState<T>()
}