diff --git a/presentation/src/main/java/com/threegap/bitnagil/presentation/common/mviviewmodel/MviViewModel.kt b/presentation/src/main/java/com/threegap/bitnagil/presentation/common/mviviewmodel/MviViewModel.kt index 1e4ad630..8a03a1c8 100644 --- a/presentation/src/main/java/com/threegap/bitnagil/presentation/common/mviviewmodel/MviViewModel.kt +++ b/presentation/src/main/java/com/threegap/bitnagil/presentation/common/mviviewmodel/MviViewModel.kt @@ -20,14 +20,35 @@ abstract class MviViewModel get() = container.stateFlow val sideEffectFlow: Flow get() = container.sideEffectFlow - protected suspend fun SimpleSyntax.sendSideEffect(sideEffect: SIDE_EFFECT) = postSideEffect(sideEffect) + /** + * Emits a side effect within the Orbit MVI syntax context. + * + * @param sideEffect The side effect to be posted. + */ +protected suspend fun SimpleSyntax.sendSideEffect(sideEffect: SIDE_EFFECT) = postSideEffect(sideEffect) + /** + * Computes a new state in response to the given intent and current state. + * + * Subclasses must implement this to define how each intent transforms the state. + * + * @param intent The intent representing a user or system action. + * @param state The current UI state. + * @return The new state if a state change should occur, or null to leave the state unchanged. + */ protected abstract suspend fun SimpleSyntax.reduceState( intent: INTENT, state: STATE, ): STATE? - fun sendIntent(intent: INTENT) = + /** + * Processes the given intent by invoking state reduction and updating the state if a new state is produced. + * + * If the `reduceState` function returns a non-null state, the container's state is updated accordingly. + * + * @param intent The intent to be handled. + */ + fun sendIntent(intent: INTENT) = intent { val newState = reduceState(intent, state)