diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 84e0ac5..db0d19f 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -85,7 +85,7 @@ kotlin { implementation("com.squareup.sqldelight:coroutines-extensions:${Versions.sqlDelight}") // koin - implementation("org.koin:koin-core:${Versions.koin}") + api("org.koin:koin-core:${Versions.koin}") } } diff --git a/common/src/commonMain/kotlin/com/surrus/common/repository/PeopleInSpaceRepository.kt b/common/src/commonMain/kotlin/com/surrus/common/repository/PeopleInSpaceRepository.kt index d26d1e0..8c28fa7 100644 --- a/common/src/commonMain/kotlin/com/surrus/common/repository/PeopleInSpaceRepository.kt +++ b/common/src/commonMain/kotlin/com/surrus/common/repository/PeopleInSpaceRepository.kt @@ -43,6 +43,8 @@ class PeopleInSpaceRepository() : KoinComponent { } } + suspend fun fetchPeople() = peopleInSpaceApi.fetchPeople().people + // called from iOS/watchOS/macOS client fun fetchPeople(success: (List) -> Unit) { GlobalScope.launch(Dispatchers.Main) { diff --git a/web/src/main/kotlin/App.kt b/web/src/main/kotlin/App.kt index e3b613e..4ee30f0 100644 --- a/web/src/main/kotlin/App.kt +++ b/web/src/main/kotlin/App.kt @@ -7,7 +7,7 @@ import kotlinx.coroutines.* val App = functionalComponent { _ -> val appDependencies = useContext(AppDependenciesContext) - val peopleInSpaceApi = appDependencies.peopleInSpaceApi + val repository = appDependencies.repository val (people, setPeople) = useState(emptyList()) @@ -15,7 +15,7 @@ val App = functionalComponent { _ -> val mainScope = MainScope() mainScope.launch { - setPeople(peopleInSpaceApi.fetchPeople().people) + setPeople(repository.fetchPeople()) } return@useEffectWithCleanup { mainScope.cancel() } } diff --git a/web/src/main/kotlin/Main.kt b/web/src/main/kotlin/Main.kt index a9c0de4..7c46a77 100644 --- a/web/src/main/kotlin/Main.kt +++ b/web/src/main/kotlin/Main.kt @@ -1,17 +1,19 @@ -import com.surrus.common.remote.PeopleInSpaceApi +import com.surrus.common.di.initKoin +import com.surrus.common.repository.PeopleInSpaceRepository import react.child import react.createContext import react.dom.render import kotlin.browser.document object AppDependencies { - val peopleInSpaceApi = PeopleInSpaceApi() + val repository = PeopleInSpaceRepository() } val AppDependenciesContext = createContext() fun main() { + initKoin() render(document.getElementById("root")) { AppDependenciesContext.Provider(AppDependencies) { child(functionalComponent = App)