kotlin/js updates including use of koin
This commit is contained in:
parent
e23bb65d04
commit
34088240e8
4 changed files with 9 additions and 5 deletions
|
@ -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}")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,8 @@ class PeopleInSpaceRepository() : KoinComponent {
|
|||
}
|
||||
}
|
||||
|
||||
suspend fun fetchPeople() = peopleInSpaceApi.fetchPeople().people
|
||||
|
||||
// called from iOS/watchOS/macOS client
|
||||
fun fetchPeople(success: (List<Assignment>) -> Unit) {
|
||||
GlobalScope.launch(Dispatchers.Main) {
|
||||
|
|
|
@ -7,7 +7,7 @@ import kotlinx.coroutines.*
|
|||
|
||||
val App = functionalComponent<RProps> { _ ->
|
||||
val appDependencies = useContext(AppDependenciesContext)
|
||||
val peopleInSpaceApi = appDependencies.peopleInSpaceApi
|
||||
val repository = appDependencies.repository
|
||||
|
||||
val (people, setPeople) = useState(emptyList<Assignment>())
|
||||
|
||||
|
@ -15,7 +15,7 @@ val App = functionalComponent<RProps> { _ ->
|
|||
val mainScope = MainScope()
|
||||
|
||||
mainScope.launch {
|
||||
setPeople(peopleInSpaceApi.fetchPeople().people)
|
||||
setPeople(repository.fetchPeople())
|
||||
}
|
||||
return@useEffectWithCleanup { mainScope.cancel() }
|
||||
}
|
||||
|
|
|
@ -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<AppDependencies>()
|
||||
|
||||
|
||||
fun main() {
|
||||
initKoin()
|
||||
render(document.getElementById("root")) {
|
||||
AppDependenciesContext.Provider(AppDependencies) {
|
||||
child(functionalComponent = App)
|
||||
|
|
Loading…
Reference in a new issue