Skip to content

Commit 7924418

Browse files
๐Ÿ“ Add docstrings to feature/#2-base_view_model
Docstrings generation was requested by @l5x5l. * #6 (comment) The following files were modified: * `presentation/src/main/java/com/threegap/bitnagil/presentation/common/mviviewmodel/MviViewModel.kt`
1 parent d28ae74 commit 7924418

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

  • presentation/src/main/java/com/threegap/bitnagil/presentation/common/mviviewmodel

โ€Žpresentation/src/main/java/com/threegap/bitnagil/presentation/common/mviviewmodel/MviViewModel.ktโ€Ž

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,35 @@ abstract class MviViewModel<STATE : MviState, SIDE_EFFECT : MviSideEffect, INTEN
2020
val stateFlow: StateFlow<STATE> get() = container.stateFlow
2121
val sideEffectFlow: Flow<SIDE_EFFECT> get() = container.sideEffectFlow
2222

23-
protected suspend fun SimpleSyntax<STATE, SIDE_EFFECT>.sendSideEffect(sideEffect: SIDE_EFFECT) = postSideEffect(sideEffect)
23+
/**
24+
* Emits a side effect within the Orbit MVI syntax context.
25+
*
26+
* @param sideEffect The side effect to be posted.
27+
*/
28+
protected suspend fun SimpleSyntax<STATE, SIDE_EFFECT>.sendSideEffect(sideEffect: SIDE_EFFECT) = postSideEffect(sideEffect)
2429

30+
/**
31+
* Computes a new state in response to the given intent and current state.
32+
*
33+
* Subclasses must implement this to define how each intent transforms the state.
34+
*
35+
* @param intent The intent representing a user or system action.
36+
* @param state The current UI state.
37+
* @return The new state if a state change should occur, or null to leave the state unchanged.
38+
*/
2539
protected abstract suspend fun SimpleSyntax<STATE, SIDE_EFFECT>.reduceState(
2640
intent: INTENT,
2741
state: STATE,
2842
): STATE?
2943

30-
fun sendIntent(intent: INTENT) =
44+
/**
45+
* Processes the given intent by invoking state reduction and updating the state if a new state is produced.
46+
*
47+
* If the `reduceState` function returns a non-null state, the container's state is updated accordingly.
48+
*
49+
* @param intent The intent to be handled.
50+
*/
51+
fun sendIntent(intent: INTENT) =
3152
intent {
3253
val newState = reduceState(intent, state)
3354

0 commit comments

Comments
ย (0)