Skip to content

Commit

Permalink
Merge pull request #43 from stslex/dev
Browse files Browse the repository at this point in the history
Store refactor
  • Loading branch information
stslex authored Nov 1, 2024
2 parents b420aaa + 924a9f9 commit 4ddca64
Show file tree
Hide file tree
Showing 14 changed files with 165 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.stslex.wizard.core.ui.viewModel

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

actual inline fun <reified R : ViewModel> Module.viewModelOf(
crossinline constructor: () -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = viewModelOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1> Module.viewModelOf(
crossinline constructor: (T1) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = viewModelOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1, reified T2> Module.viewModelOf(
crossinline constructor: (T1, T2) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = viewModelOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1, reified T2, reified T3> Module.viewModelOf(
crossinline constructor: (T1, T2, T3) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = viewModelOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4> Module.viewModelOf(
crossinline constructor: (T1, T2, T3, T4) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = viewModelOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5> Module.viewModelOf(
crossinline constructor: (T1, T2, T3, T4, T5) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = viewModelOf(constructor, options)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.stslex.wizard.core.ui.mvi

import com.stslex.wizard.core.ui.viewModel.viewModelOf
import org.koin.core.definition.BeanDefinition
import org.koin.core.definition.KoinDefinition
import org.koin.core.module.Module

inline fun <reified R : Store<*, *, *, *>> Module.storeOf(
crossinline constructor: () -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R> = viewModelOf(constructor, options)

inline fun <reified R : Store<*, *, *, *>, reified T1> Module.storeOf(
crossinline constructor: (T1) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R> = viewModelOf(constructor, options)

inline fun <reified R : Store<*, *, *, *>, reified T1, reified T2> Module.storeOf(
crossinline constructor: (T1, T2) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R> = viewModelOf(constructor, options)

inline fun <reified R : Store<*, *, *, *>, reified T1, reified T2, reified T3> Module.storeOf(
crossinline constructor: (T1, T2, T3) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R> = viewModelOf(constructor, options)

inline fun <reified R : Store<*, *, *, *>, reified T1, reified T2, reified T3, reified T4> Module.storeOf(
crossinline constructor: (T1, T2, T3, T4) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R> = viewModelOf(constructor, options)

inline fun <reified R : Store<*, *, *, *>, reified T1, reified T2, reified T3, reified T4, reified T5> Module.storeOf(
crossinline constructor: (T1, T2, T3, T4, T5) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R> = viewModelOf(constructor, options)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.stslex.wizard.core.ui.viewModel

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

expect inline fun <reified R : ViewModel> Module.viewModelOf(
crossinline constructor: () -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R>

expect inline fun <reified R : ViewModel, reified T1> Module.viewModelOf(
crossinline constructor: (T1) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R>

expect inline fun <reified R : ViewModel, reified T1, reified T2> Module.viewModelOf(
crossinline constructor: (T1, T2) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R>

expect inline fun <reified R : ViewModel, reified T1, reified T2, reified T3> Module.viewModelOf(
crossinline constructor: (T1, T2, T3) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R>

expect inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4> Module.viewModelOf(
crossinline constructor: (T1, T2, T3, T4) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R>

expect inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5> Module.viewModelOf(
crossinline constructor: (T1, T2, T3, T4, T5) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)? = null,
): KoinDefinition<R>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.stslex.wizard.core.ui.viewModel

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

actual inline fun <reified R : ViewModel> Module.viewModelOf(
crossinline constructor: () -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = factoryOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1> Module.viewModelOf(
crossinline constructor: (T1) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = factoryOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1, reified T2> Module.viewModelOf(
crossinline constructor: (T1, T2) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = factoryOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1, reified T2, reified T3> Module.viewModelOf(
crossinline constructor: (T1, T2, T3) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = factoryOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4> Module.viewModelOf(
crossinline constructor: (T1, T2, T3, T4) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = factoryOf(constructor, options)

actual inline fun <reified R : ViewModel, reified T1, reified T2, reified T3, reified T4, reified T5> Module.viewModelOf(
crossinline constructor: (T1, T2, T3, T4, T5) -> R,
noinline options: (BeanDefinition<R>.() -> Unit)?,
): KoinDefinition<R> = factoryOf(constructor, options)
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.mvi.storeDefinition
import com.stslex.wizard.core.ui.mvi.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 All @@ -21,12 +21,6 @@ class ModuleFeatureAuth : AppModule() {
factoryOf(::AuthRepositoryImpl) { bind<AuthRepository>() }
factoryOf(::AuthInteractorImpl) { bind<AuthInteractor>() }
factoryOf(::AuthRouterImpl) { bind<AuthRouter>() }
storeDefinition {
AuthStore(
interactor = get(),
router = get(),
dispatcher = get()
)
}
storeOf(::AuthStore)
}
}
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.mvi.storeDefinition
import com.stslex.wizard.core.ui.mvi.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 All @@ -21,13 +21,6 @@ class ModuleFeatureFavourite : AppModule() {
factoryOf(::FavouriteRepositoryImpl) { bind<FavouriteRepository>() }
factoryOf(::FavouriteInteractorImpl) { bind<FavouriteInteractor>() }
factoryOf(::FavouriteRouterImpl) { bind<FavouriteRouter>() }
storeDefinition {
FavouriteStore(
interactor = get(),
appDispatcher = get(),
router = get(),
pagingFactory = get()
)
}
storeOf(::FavouriteStore)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.film.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.mvi.storeDefinition
import com.stslex.wizard.core.ui.mvi.storeOf
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 @@ -18,13 +18,7 @@ import org.koin.dsl.ModuleDeclaration
class ModuleFeatureFilm : AppModule() {

override fun declaration(): ModuleDeclaration = {
storeDefinition {
FilmStore(
interactor = get(),
appDispatcher = get(),
router = get(),
)
}
storeOf(::FilmStore)
factoryOf(::FilmRouterImpl) { bind<FilmRouter>() }
factoryOf(::FilmInteractorImpl) { bind<FilmInteractor>() }
factoryOf(::FilmRepositoryImpl) { bind<FilmRepository>() }
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.mvi.storeDefinition
import com.stslex.wizard.core.ui.mvi.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 All @@ -18,13 +18,7 @@ import org.koin.dsl.ModuleDeclaration
class ModuleFeatureFeed : AppModule() {

override fun declaration(): ModuleDeclaration = {
storeDefinition {
FeedStore(
interactor = get(),
appDispatcher = get(),
router = get()
)
}
storeOf(::FeedStore)
factoryOf(::FeedScreenRouterImpl) { bind<FeedScreenRouter>() }
factoryOf(::FeedInteractorImpl) { bind<FeedInteractor>() }
factoryOf(::FeedRepositoryImpl) { bind<FeedRepository>() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.follower.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.mvi.storeDefinition
import com.stslex.wizard.core.ui.mvi.storeOf
import com.stslex.wizard.feature.follower.data.repository.FollowerRepository
import com.stslex.wizard.feature.follower.data.repository.FollowerRepositoryImpl
import com.stslex.wizard.feature.follower.domain.interactor.FollowerInteractor
Expand All @@ -21,13 +21,6 @@ class ModuleFeatureFollower : AppModule() {
factoryOf(::FollowerRepositoryImpl) { bind<FollowerRepository>() }
factoryOf(::FollowerInteractorImpl) { bind<FollowerInteractor>() }
factoryOf(::FollowerRouterImpl) { bind<FollowerRouter>() }
storeDefinition {
FollowerStore(
interactor = get(),
appDispatcher = get(),
router = get(),
pagerFactory = get(),
)
}
storeOf(::FollowerStore)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.match.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.mvi.storeDefinition
import com.stslex.wizard.core.ui.mvi.storeOf
import com.stslex.wizard.feature.match.data.repository.MatchRepository
import com.stslex.wizard.feature.match.data.repository.MatchRepositoryImpl
import com.stslex.wizard.feature.match.domain.interactor.MatchInteractor
Expand All @@ -21,14 +21,6 @@ class ModuleFeatureMatch : AppModule() {
factoryOf(::MatchRepositoryImpl) { bind<MatchRepository>() }
factoryOf(::MatchInteractorImpl) { bind<MatchInteractor>() }
factoryOf(::MatchRouterImpl) { bind<MatchRouter>() }
storeDefinition {
MatchStore(
interactor = get(),
router = get(),
appDispatcher = get(),
userStore = get(),
pagerFactory = get()
)
}
storeOf(::MatchStore)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MatchStore(
updateState { currentState ->
currentState.copy(
isSelf = action.type == Screen.Match.Type.SELF,
uuid = action.uuid.ifBlank { userStore.uuid } ,
uuid = action.uuid.ifBlank { userStore.uuid },
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.match_feed.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.mvi.storeDefinition
import com.stslex.wizard.core.ui.mvi.storeOf
import com.stslex.wizard.feature.match_feed.data.repository.MatchFeedMockRepositoryImpl
import com.stslex.wizard.feature.match_feed.data.repository.MatchFeedRepository
import com.stslex.wizard.feature.match_feed.domain.MatchFeedInteractor
Expand All @@ -21,12 +21,6 @@ class ModuleFeatureMatchFeed : AppModule() {
factoryOf(::MatchFeedMockRepositoryImpl) { bind<MatchFeedRepository>() }
factoryOf(::MatchFeedInteractorImpl) { bind<MatchFeedInteractor>() }
factoryOf(::MatchFeedRouterImpl) { bind<MatchFeedRouter>() }
storeDefinition {
MatchFeedStore(
interactor = get(),
appDispatcher = get(),
router = get()
)
}
storeOf(::MatchFeedStore)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.profile.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.mvi.storeDefinition
import com.stslex.wizard.core.ui.mvi.storeOf
import com.stslex.wizard.feature.profile.data.repository.ProfileRepository
import com.stslex.wizard.feature.profile.data.repository.ProfileRepositoryImpl
import com.stslex.wizard.feature.profile.domain.interactor.ProfileInteractor
Expand All @@ -18,14 +18,7 @@ import org.koin.dsl.ModuleDeclaration
class ModuleFeatureProfile : AppModule() {

override fun declaration(): ModuleDeclaration = {
storeDefinition {
ProfileStore(
interactor = get(),
userStore = get(),
appDispatcher = get(),
router = get(),
)
}
storeOf(::ProfileStore)
factoryOf(::ProfileRouterImpl) { bind<ProfileRouter>() }
factoryOf(::ProfileInteractorImpl) { bind<ProfileInteractor>() }
factoryOf(::ProfileRepositoryImpl) { bind<ProfileRepository>() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stslex.wizard.feature.settings.di

import com.stslex.wizard.core.core.AppModule
import com.stslex.wizard.core.ui.mvi.storeDefinition
import com.stslex.wizard.core.ui.mvi.storeOf
import com.stslex.wizard.feature.settings.domain.SettingsInteractor
import com.stslex.wizard.feature.settings.domain.SettingsInteractorImpl
import com.stslex.wizard.feature.settings.navigation.SettingsRouter
Expand All @@ -18,12 +18,6 @@ class ModuleFeatureSettings : AppModule() {
override fun declaration(): ModuleDeclaration = {
factoryOf(::SettingsInteractorImpl) { bind<SettingsInteractor>() }
factoryOf(::SettingsRouterImpl) { bind<SettingsRouter>() }
storeDefinition {
SettingsStore(
interactor = get(),
appDispatcher = get(),
router = get(),
)
}
storeOf(::SettingsStore)
}
}

0 comments on commit 4ddca64

Please sign in to comment.