Last active
January 26, 2022 02:49
-
-
Save fededri/9736665fbb6c18b14b807aefbc36dae2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typealias NextResult = Next<MoviesState, MoviesEffects, MovieEvents> | |
class MoviesUpdater : Updater<MoviesActions, MoviesState, MoviesEffects, MovieEvents> { | |
override fun onNewAction( | |
action: MoviesActions, | |
currentState: MoviesState | |
): Next<MoviesState, MoviesEffects, MovieEvents> { | |
return when (action) { | |
is MoviesActions.FetchMovies -> fetchMovies(action, currentState) | |
is MoviesActions.SaveMovies -> saveMovies(action, currentState) | |
is MoviesActions.SelectMovie -> selectMovie(action, currentState) | |
} | |
} | |
private fun selectMovie(action: MoviesActions.SelectMovie, state: MoviesState): NextResult { | |
return Next.StateWithEvents( | |
state.copy(selectedMovie = action.movie), | |
setOf(MovieEvents.OpenSelectedMovie(action.movie)) | |
) | |
} | |
private fun saveMovies(action: MoviesActions.SaveMovies, state: MoviesState): NextResult { | |
return Next.State(state.copy(movies = action.movies)) | |
} | |
private fun fetchMovies(action: MoviesActions.FetchMovies, state: MoviesState): NextResult { | |
return Next.StateWithSideEffects(state, setOf(MoviesEffects.LoadMovies(action.type))) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment