Skip to content

Commit

Permalink
Merge pull request #49 from stslex/dev
Browse files Browse the repository at this point in the history
mvi module
  • Loading branch information
stslex authored Dec 9, 2024
2 parents 57a6851 + d3bf87e commit 4ef6b53
Show file tree
Hide file tree
Showing 69 changed files with 103 additions and 129 deletions.
1 change: 1 addition & 0 deletions commonApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ kotlin {
implementation(project(":core:network:api"))
implementation(project(":core:database"))
implementation(project(":core:ui:kit"))
implementation(project(":core:ui:mvi"))
implementation(project(":core:navigation"))

implementation(project(":feature:film_feed"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext

class AppCoroutineScopeImpl(
private val scope: CoroutineScope,
) : AppCoroutineScope {
// todo: add dispatchers from di
class AppCoroutineScopeImpl(private val scope: CoroutineScope) : AppCoroutineScope {

private fun exceptionHandler(
eachDispatcher: CoroutineDispatcher,
Expand Down

This file was deleted.

This file was deleted.

12 changes: 12 additions & 0 deletions core/ui/mvi/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
plugins {
alias(libs.plugins.convention.kmp.library.compose)
}

kotlin {
sourceSets {
commonMain.dependencies {
implementation(project(":core:core"))
implementation(project(":core:ui:kit"))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.stslex.wizard.core.ui.kit.viewModel
package com.stslex.wizard.core.ui.mvi.store_di

import androidx.lifecycle.ViewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.core.definition.BeanDefinition
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.Module
import org.koin.core.module.dsl.viewModelOf

actual inline fun <reified R : ViewModel> Module.viewModelOf(
crossinline constructor: () -> R,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package com.stslex.wizard.core.ui.kit.mvi
package com.stslex.wizard.core.ui.mvi

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.stslex.wizard.core.core.AppDispatcher
import com.stslex.wizard.core.core.AppDispatcherImpl
import com.stslex.wizard.core.core.Logger
import com.stslex.wizard.core.core.coroutine.AppCoroutineScope
import com.stslex.wizard.core.core.coroutine.AppCoroutineScopeImpl
import com.stslex.wizard.core.core.coroutineExceptionHandler
import com.stslex.wizard.core.ui.kit.mvi.Store.Action
import com.stslex.wizard.core.ui.kit.mvi.Store.Event
import com.stslex.wizard.core.ui.kit.mvi.Store.State
import com.stslex.wizard.core.ui.mvi.Store.Action
import com.stslex.wizard.core.ui.mvi.Store.Event
import com.stslex.wizard.core.ui.mvi.Store.State
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineExceptionHandler
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
Expand Down Expand Up @@ -50,15 +47,6 @@ abstract class BaseStore<S : State, A : Action, E : Event>(initialState: S) : Vi
/** Process the action. This method should be overridden in the child class.*/
protected abstract fun process(action: A)

private fun exceptionHandler(
onError: suspend (cause: Throwable) -> Unit = {},
) = CoroutineExceptionHandler { _, throwable ->
Logger.e(throwable)
viewModelScope.launch(coroutineExceptionHandler) {
onError(throwable)
}
}

/**
* Updates the state of the screen.
* @param update - function that updates the state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.ui.kit.mvi
package com.stslex.wizard.core.ui.mvi

import androidx.compose.material3.SnackbarDuration
import androidx.compose.runtime.Stable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.stslex.wizard.core.ui.kit.mvi
package com.stslex.wizard.core.ui.mvi

fun interface Router<in E : Store.Action.Navigation> {

operator fun invoke(event: E)
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.stslex.wizard.core.ui.kit.mvi
package com.stslex.wizard.core.ui.mvi

import com.stslex.wizard.core.ui.kit.mvi.Store.Action
import com.stslex.wizard.core.ui.kit.mvi.Store.Event
import com.stslex.wizard.core.ui.kit.mvi.Store.State
import com.stslex.wizard.core.ui.mvi.Store.Action
import com.stslex.wizard.core.ui.mvi.Store.Event
import com.stslex.wizard.core.ui.mvi.Store.State
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.stslex.wizard.core.ui.kit.mvi
package com.stslex.wizard.core.ui.mvi.store_di

import com.stslex.wizard.core.ui.kit.viewModel.viewModelOf
import com.stslex.wizard.core.ui.mvi.BaseStore
import org.koin.core.definition.BeanDefinition
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.Module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package com.stslex.wizard.core.ui.kit.mvi
package com.stslex.wizard.core.ui.mvi.store_di

import androidx.compose.runtime.Composable
import androidx.lifecycle.ViewModel
import com.stslex.wizard.core.ui.mvi.Store
import org.koin.compose.koinInject
import org.koin.core.definition.Definition
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.Module
import org.koin.core.parameter.ParametersDefinition
import org.koin.core.qualifier.Qualifier

expect inline fun <reified T : ViewModel> Module.viewModelDefinition(
qualifier: Qualifier? = null,
noinline definition: Definition<T>
): KoinDefinition<T>

@Composable
inline fun <reified T : Store<*, *, *>> getStore(
qualifier: Qualifier? = null,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.ui.kit.viewModel
package com.stslex.wizard.core.ui.mvi.store_di

import androidx.lifecycle.ViewModel
import org.koin.core.definition.BeanDefinition
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.stslex.wizard.core.ui.kit.viewModel
package com.stslex.wizard.core.ui.mvi.store_di

import androidx.lifecycle.ViewModel
import org.koin.core.definition.BeanDefinition
Expand Down
1 change: 1 addition & 0 deletions feature/auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ kotlin {
commonMain.dependencies {
implementation(project(":core:core"))
implementation(project(":core:ui:kit"))
implementation(project(":core:ui:mvi"))
implementation(project(":core:navigation"))
implementation(project(":core:network:api"))
implementation(project(":core:database"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.auth.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.kit.mvi.storeOf
import com.stslex.wizard.core.ui.mvi.store_di.storeOf
import com.stslex.wizard.feature.auth.data.AuthRepository
import com.stslex.wizard.feature.auth.data.AuthRepositoryImpl
import com.stslex.wizard.feature.auth.domain.AuthInteractor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.compose.runtime.remember
import androidx.navigation.NavGraphBuilder
import com.stslex.wizard.core.navigation.Screen
import com.stslex.wizard.core.navigation.navScreen
import com.stslex.wizard.core.ui.kit.mvi.getStore
import com.stslex.wizard.core.ui.mvi.store_di.getStore
import com.stslex.wizard.feature.auth.ui.AuthScreen
import com.stslex.wizard.feature.auth.ui.model.screen.rememberAuthScreenState
import com.stslex.wizard.feature.auth.ui.store.AuthStore
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.stslex.wizard.feature.auth.navigation

import com.stslex.wizard.core.ui.kit.mvi.Router
import com.stslex.wizard.core.ui.mvi.Router
import com.stslex.wizard.feature.auth.ui.store.AuthStore

interface AuthRouter : Router<AuthStore.Action.Navigation>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.auth.ui.store

import com.stslex.wizard.core.ui.kit.mvi.CommonEvents
import com.stslex.wizard.core.ui.kit.mvi.Store
import com.stslex.wizard.core.ui.mvi.CommonEvents
import com.stslex.wizard.core.ui.mvi.Store
import com.stslex.wizard.feature.auth.ui.store.AuthStore.Action
import com.stslex.wizard.feature.auth.ui.store.AuthStore.Event
import com.stslex.wizard.feature.auth.ui.store.AuthStore.State
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.auth.ui.store

import com.stslex.wizard.core.ui.kit.mvi.BaseStore
import com.stslex.wizard.core.ui.kit.mvi.CommonEvents.Snackbar
import com.stslex.wizard.core.ui.mvi.BaseStore
import com.stslex.wizard.core.ui.mvi.CommonEvents.Snackbar
import com.stslex.wizard.feature.auth.domain.AuthInteractor
import com.stslex.wizard.feature.auth.navigation.AuthRouter
import com.stslex.wizard.feature.auth.ui.store.AuthStore.Action
Expand Down
1 change: 1 addition & 0 deletions feature/favourite/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ kotlin {
sourceSets.commonMain.dependencies {
implementation(project(":core:core"))
implementation(project(":core:ui:kit"))
implementation(project(":core:ui:mvi"))
implementation(project(":core:network:api"))
implementation(project(":core:navigation"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.favourite.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.kit.mvi.storeOf
import com.stslex.wizard.core.ui.mvi.store_di.storeOf
import com.stslex.wizard.feature.favourite.data.repository.FavouriteRepository
import com.stslex.wizard.feature.favourite.data.repository.FavouriteRepositoryImpl
import com.stslex.wizard.feature.favourite.domain.interactor.FavouriteInteractor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.runtime.remember
import androidx.navigation.NavGraphBuilder
import com.stslex.wizard.core.navigation.Screen
import com.stslex.wizard.core.navigation.navScreen
import com.stslex.wizard.core.ui.kit.mvi.getStore
import com.stslex.wizard.core.ui.mvi.store_di.getStore
import com.stslex.wizard.feature.favourite.ui.FavouriteScreen
import com.stslex.wizard.feature.favourite.ui.store.FavouriteStore
import com.stslex.wizard.feature.favourite.ui.store.FavouriteStore.Action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.stslex.wizard.feature.favourite.navigation

import com.stslex.wizard.core.ui.kit.mvi.Router
import com.stslex.wizard.core.ui.mvi.Router
import com.stslex.wizard.feature.favourite.ui.store.FavouriteStore

interface FavouriteRouter : Router<FavouriteStore.Action.Navigation>
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.stslex.wizard.feature.favourite.ui.store
import androidx.compose.runtime.Stable
import com.stslex.wizard.core.ui.kit.base.paging.PagingConfig
import com.stslex.wizard.core.ui.kit.base.paging.PagingUiState
import com.stslex.wizard.core.ui.kit.mvi.CommonEvents
import com.stslex.wizard.core.ui.kit.mvi.Store
import com.stslex.wizard.core.ui.mvi.CommonEvents
import com.stslex.wizard.core.ui.mvi.Store
import com.stslex.wizard.feature.favourite.ui.model.FavouriteModel
import com.stslex.wizard.feature.favourite.ui.store.FavouriteStore.Action
import com.stslex.wizard.feature.favourite.ui.store.FavouriteStore.Event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.stslex.wizard.feature.favourite.ui.store
import com.stslex.wizard.core.core.AppDispatcher
import com.stslex.wizard.core.ui.kit.base.mapToAppError
import com.stslex.wizard.core.ui.kit.base.paging.toUi
import com.stslex.wizard.core.ui.kit.mvi.BaseStore
import com.stslex.wizard.core.ui.kit.mvi.CommonEvents.Snackbar
import com.stslex.wizard.core.ui.mvi.BaseStore
import com.stslex.wizard.core.ui.mvi.CommonEvents.Snackbar
import com.stslex.wizard.core.ui.kit.pager.pager.StorePager
import com.stslex.wizard.core.ui.kit.pager.pager.StorePagerFactory
import com.stslex.wizard.core.ui.kit.pager.states.PagerLoadState
Expand Down
1 change: 1 addition & 0 deletions feature/film/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ kotlin {
implementation(project(":core:core"))
implementation(project(":core:ui:kit"))
implementation(project(":core:ui:image"))
implementation(project(":core:ui:mvi"))
implementation(project(":core:network:api"))
implementation(project(":core:database"))
implementation(project(":core:navigation"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.stslex.wizard.feature.film.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.kit.mvi.storeOf
import com.stslex.wizard.core.ui.mvi.store_di.storeOf
import com.stslex.wizard.core.ui.mvi.store_di.viewModelOf
import com.stslex.wizard.feature.film.data.repository.FilmRepository
import com.stslex.wizard.feature.film.data.repository.FilmRepositoryImpl
import com.stslex.wizard.feature.film.domain.interactor.FilmInteractor
Expand All @@ -19,6 +20,7 @@ import org.koin.dsl.ModuleDeclaration
class ModuleFeatureFilm : AppModule() {

override fun declaration(): ModuleDeclaration = {
viewModelOf(::FilmStoreImpl) { bind<FilmStore>() }
storeOf(::FilmStoreImpl) { bind<FilmStore>() }
factoryOf(::FilmRouterImpl) { bind<FilmRouter>() }
factoryOf(::FilmInteractorImpl) { bind<FilmInteractor>() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.stslex.wizard.feature.film.navigation

import com.stslex.wizard.core.ui.kit.mvi.Router
import com.stslex.wizard.core.ui.mvi.Router
import com.stslex.wizard.feature.film.ui.store.FilmStore

interface FilmRouter : Router<FilmStore.Action.Navigation>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.runtime.remember
import androidx.navigation.NavGraphBuilder
import com.stslex.wizard.core.navigation.Screen
import com.stslex.wizard.core.navigation.navScreen
import com.stslex.wizard.core.ui.kit.mvi.getStore
import com.stslex.wizard.core.ui.mvi.store_di.getStore
import com.stslex.wizard.feature.film.ui.FilmScreen
import com.stslex.wizard.feature.film.ui.store.FilmStore
import com.stslex.wizard.feature.film.ui.store.FilmStore.Action
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.film.ui.store

import androidx.compose.runtime.Stable
import com.stslex.wizard.core.ui.kit.mvi.Store
import com.stslex.wizard.core.ui.mvi.Store
import com.stslex.wizard.feature.film.ui.store.FilmStore.Action
import com.stslex.wizard.feature.film.ui.store.FilmStore.Event
import com.stslex.wizard.feature.film.ui.store.FilmStore.State
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.stslex.wizard.feature.film.ui.store

import com.stslex.wizard.core.ui.kit.mvi.BaseStore
import com.stslex.wizard.core.ui.mvi.BaseStore
import com.stslex.wizard.feature.film.domain.interactor.FilmInteractor
import com.stslex.wizard.feature.film.navigation.FilmRouter
import com.stslex.wizard.feature.film.ui.model.toDomain
Expand Down
1 change: 1 addition & 0 deletions feature/film_feed/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ kotlin {
implementation(project(":core:core"))
implementation(project(":core:ui:kit"))
implementation(project(":core:ui:image"))
implementation(project(":core:ui:mvi"))
implementation(project(":core:network:api"))
implementation(project(":core:navigation"))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.film_feed.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.kit.mvi.storeOf
import com.stslex.wizard.core.ui.mvi.store_di.storeOf
import com.stslex.wizard.feature.film_feed.data.repository.FeedRepository
import com.stslex.wizard.feature.film_feed.data.repository.FeedRepositoryImpl
import com.stslex.wizard.feature.film_feed.domain.interactor.FeedInteractor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.stslex.wizard.feature.film_feed.navigation

import com.stslex.wizard.core.ui.kit.mvi.Router
import com.stslex.wizard.core.ui.mvi.Router
import com.stslex.wizard.feature.film_feed.ui.store.FeedStore.Action.Navigation

interface FeedScreenRouter : Router<Navigation>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import androidx.compose.runtime.remember
import androidx.navigation.NavGraphBuilder
import com.stslex.wizard.core.navigation.Screen
import com.stslex.wizard.core.navigation.navScreen
import com.stslex.wizard.core.ui.kit.mvi.getStore
import com.stslex.wizard.core.ui.mvi.store_di.getStore
import com.stslex.wizard.feature.film_feed.ui.FeedScreen
import com.stslex.wizard.feature.film_feed.ui.store.FeedStore
import com.stslex.wizard.feature.film_feed.ui.store.FeedStore.Action
Expand Down
Loading

0 comments on commit 4ef6b53

Please sign in to comment.