-
Notifications
You must be signed in to change notification settings - Fork 0
/
MVI ViewModel.kt
49 lines (39 loc) · 1.24 KB
/
MVI ViewModel.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME}
#end
#parse("File Header.java")
import ro.horatiu_udrea.mvi.base.IntentHandler
import ro.horatiu_udrea.mvi.handlers.Run
import ro.horatiu_udrea.mvi.handlers.RunIfNotRunning
typealias S = ${VIEWMODEL_NAME}State
typealias I = ${VIEWMODEL_NAME}Intent
typealias D = ${VIEWMODEL_NAME}Dependencies
class ${VIEWMODEL_NAME}ViewModel(dependencies: D) : MVIViewModel<S, I, D>(initialState = ${VIEWMODEL_NAME}State(), dependencies) {
override fun onIntent(
intent: I,
sendIntent: (I) -> Unit
) = Unit
override fun onStateChange(
description: String,
sourceIntent: I,
oldState: S,
newState: S,
sendIntent: (I) -> Unit
) = Unit
override fun onException(
intent: I,
exception: Throwable,
sendIntent: (I) -> Unit
) {
super.onException(intent, exception, sendIntent)
}
}
data class ${VIEWMODEL_NAME}State(
val state: Unit = Unit
)
sealed interface ${VIEWMODEL_NAME}Intent : IntentHandler<S, I, D> {
data object Initialize : I, RunIfNotRunning<S, I, D>({ state ->
state.change("Description") { oldState -> oldState.copy() }
})
}
class ${VIEWMODEL_NAME}Dependencies(
)