Skip to content

Commit

Permalink
feat: Changes in Processor (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
tallnato authored Dec 6, 2024
1 parent 74bc12a commit 49cdf58
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch

abstract class ViewModel<I : Intent, R : Result, S : State, E : Effect>(
abstract class ViewModel<I : Intent, R : Result, E : Effect, S : State>(
initialState: S,
private val processor: Processor<I, R, S>,
private val processor: Processor<I, S>,
private val reducer: Reducer<R, S>,
private val computationDispatcher: CoroutineDispatcher = Dispatchers.Default,
private val mainDispatcher: CoroutineDispatcher = Dispatchers.Main
Expand All @@ -47,7 +47,7 @@ abstract class ViewModel<I : Intent, R : Result, S : State, E : Effect>(
.onEach { result ->
when (result) {
is Effect -> _effects.emit(result as E)
is Action -> _state.update { state -> reducer.reduce(result, state) }
is Action -> _state.update { state -> reducer.reduce(result as R, state) }
}
}
.flowOn(mainDispatcher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.Flow
* intentions ([Intent]s) and determining the appropriate actions or data changes ([Result]s)
* required to update the application's [State].
*/
interface Processor<I : Intent, R : Result, S : State> {
interface Processor<I : Intent, S : State> {

/**
* Processes an [Intent] and emits a stream of [Result]s based on the current [State].
Expand All @@ -18,5 +18,5 @@ interface Processor<I : Intent, R : Result, S : State> {
* @param state The current [State] of the relevant part of the application.
* @return A [Flow] of [Result]s that represent the actions or data changes needed to update the state.
*/
fun process(input: I, state: S): Flow<R>
fun process(input: I, state: S): Flow<Result>
}

0 comments on commit 49cdf58

Please sign in to comment.