Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix defaut extra argument in Fragment.activityViewModel #1699

Merged
merged 2 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.koin.androidx.viewmodel.ext.android

import android.app.Activity
import androidx.activity.ComponentActivity
import androidx.annotation.MainThread
import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
Expand Down Expand Up @@ -66,10 +68,11 @@ inline fun <reified T : ViewModel> Fragment.getActivityViewModel(
noinline extrasProducer: (() -> CreationExtras)? = null,
noinline parameters: (() -> ParametersHolder)? = null,
): T {
val op = ownerProducer()
return resolveViewModel(
T::class,
ownerProducer().viewModelStore,
extras = extrasProducer?.invoke() ?: this.defaultViewModelCreationExtras,
op.viewModelStore,
extras = extrasProducer?.invoke() ?: (op as? ComponentActivity)?.defaultViewModelCreationExtras ?: this.defaultViewModelCreationExtras,
qualifier = qualifier,
parameters = parameters,
scope = getKoinScope()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package org.koin.ktor.ext

import io.ktor.server.application.*
import io.ktor.server.testing.*
import org.junit.After
import org.junit.Assert.*
import org.junit.Test
import org.koin.core.annotation.KoinReflectAPI
import org.koin.core.context.stopKoin
import org.koin.dsl.module
import org.koin.ktor.plugin.Koin
import org.koin.ktor.plugin.KoinIsolated
Expand All @@ -22,6 +24,11 @@ class Bar2(val name: String = "")
@OptIn(KoinReflectAPI::class)
class KoinFeatureTest {

@After
fun after(){
stopKoin()
}

@Test
fun `can install feature`() {
val module = module {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import io.ktor.server.testing.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withTimeout
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin
import org.koin.core.logger.Level
import org.koin.dsl.module
import org.koin.ktor.plugin.Koin
Expand All @@ -39,6 +41,11 @@ import kotlin.test.assertTrue

class KoinPluginRunTest {

@Before
fun before(){
stopKoin()
}

@Test
fun `minimalistic app run`() {
testMyApplication {
Expand All @@ -50,7 +57,6 @@ class KoinPluginRunTest {
}

@Test
@Ignore
fun `run outside context`() = runBlocking<Unit> {
var counter = 0
startKoin {
Expand Down
Loading