VictorKabata / Notflix

Kotlin Multiplatform playground
589 stars 82 forks source link

why RepositoryImpls are using flowOf() #50

Closed periva101 closed 2 years ago

periva101 commented 2 years ago

I want to thank you first, then I hope you answer my question, it is a question, not an issue 😃

All ApiService methods are returning suspend functions suspend fun fetchMovieDetails(movieId: Int): MovieDetailsDto?

why are MovieDetailsRepositoryImpl methods had converted toflowOf () e.g

    override suspend fun getMovieDetails(movieId: Int): Flow<MovieDetails?> {
        val networkResponse = apiService.fetchMovieDetails(movieId = movieId)

        return flowOf(networkResponse?.toDomain())
    }

what are the benefits of making all repo methods in kotlin flow, where consuming suspend fun is easier than flow? also combing two suspend funs is much easier to combine two flows to create new usecases.

I see this pattern I would like to know the secret behind 😎

periva101 commented 2 years ago

@VictorKabata @MartinMugambi @Kagiri11

Kagiri11 commented 2 years ago

@periva101 this is no secret behind it. It's just that we want to expose a flow of MovieDetails from the repo layer.

VictorKabata commented 2 years ago

@periva101 This will make it easier to add caching later. I'm expecting whatever caching lib we decide to use will return Flow<List<Movies>> that is why we are using flowOf() though It has no "real" functional use at the moment.