-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#113 change viewModelScope ability and test sample for LoginViewModel
- Loading branch information
Showing
25 changed files
with
228 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 0 additions & 11 deletions
11
mvvm-core/src/androidMain/kotlin/dev/icerock/moko/mvvm/UI.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright 2019 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
plugins { | ||
plugin(Deps.Plugins.androidLibrary) | ||
plugin(Deps.Plugins.kotlinMultiplatform) | ||
plugin(Deps.Plugins.mobileMultiplatform) | ||
plugin(Deps.Plugins.mavenPublish) | ||
} | ||
|
||
group = "dev.icerock.moko" | ||
version = Deps.mokoMvvmVersion | ||
|
||
dependencies { | ||
commonMainApi(Deps.Libs.MultiPlatform.coroutines) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="dev.icerock.moko.mvvm.internal" /> |
10 changes: 10 additions & 0 deletions
10
mvvm-internal/src/androidMain/kotlin/dev/icerock/moko/mvvm/internal/createUIDispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.mvvm.internal | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
import kotlinx.coroutines.Dispatchers | ||
|
||
actual fun createUIDispatcher(): CoroutineDispatcher = Dispatchers.Main |
9 changes: 9 additions & 0 deletions
9
mvvm-internal/src/commonMain/kotlin/dev/icerock/moko/mvvm/internal/createUIDispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.mvvm.internal | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
|
||
expect fun createUIDispatcher(): CoroutineDispatcher |
19 changes: 19 additions & 0 deletions
19
mvvm-internal/src/commonMain/kotlin/dev/icerock/moko/mvvm/internal/createViewModelScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.mvvm.internal | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
import kotlin.native.concurrent.ThreadLocal | ||
|
||
/** | ||
* Factory of viewModelScope. Internal API, for ability of mvvm-test to change viewModelScope | ||
* dispatcher. | ||
* | ||
* In default implementation create main-thread dispatcher scope. | ||
*/ | ||
@ThreadLocal | ||
var createViewModelScope: () -> CoroutineScope = { | ||
CoroutineScope(createUIDispatcher()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
mvvm-internal/src/iosMain/kotlin/dev/icerock/moko/mvvm/internal/createUIDispatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.mvvm.internal | ||
|
||
import kotlinx.coroutines.CoroutineDispatcher | ||
|
||
actual fun createUIDispatcher(): CoroutineDispatcher = UIDispatcher() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
mvvm-test/src/commonMain/kotlin/dev/icerock/moko/mvvm/test/TestObserver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.mvvm.test | ||
|
||
class TestObserver<T> : (T) -> Unit { | ||
private var _invokeCount: Int = 0 | ||
val invokeCount: Int get() = _invokeCount | ||
|
||
private var _lastObservedValue: T? = null | ||
val lastObservedValue: T? get() = _lastObservedValue | ||
|
||
override fun invoke(p1: T) { | ||
_lastObservedValue = p1 | ||
_invokeCount++ | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
mvvm-test/src/commonMain/kotlin/dev/icerock/moko/mvvm/test/TestViewModelScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright 2021 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package dev.icerock.moko.mvvm.test | ||
|
||
import dev.icerock.moko.mvvm.internal.createViewModelScope | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlin.native.concurrent.ThreadLocal | ||
|
||
@ThreadLocal | ||
object TestViewModelScope { | ||
private val originalScope = createViewModelScope | ||
|
||
fun setupViewModelScope(coroutineScope: CoroutineScope) { | ||
createViewModelScope = { coroutineScope } | ||
} | ||
|
||
fun resetViewModelScope() { | ||
createViewModelScope = originalScope | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.