Skip to content

Commit

Permalink
v 1.0.7. Boost the performance of getting mvbScope.
Browse files Browse the repository at this point in the history
  • Loading branch information
WilliamKwokX committed Sep 24, 2023
1 parent 8010f2d commit 3e760af
Show file tree
Hide file tree
Showing 47 changed files with 320 additions and 237 deletions.
39 changes: 39 additions & 0 deletions .idea/androidTestResultsUserPreferences.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ tasks.withType(KotlinCompile).configureEach{
// publish
mavenPublishing {
def artifactId = "mvb-android"
def version = "1.0.6"
def version = "1.0.7"
def isSnapshot = false

if (isSnapshot) version += "-SNAPSHOT"
Expand Down
50 changes: 50 additions & 0 deletions api/src/androidTest/java/pers/shawxingkwok/mvb/Scope.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package pers.shawxingkwok.mvb

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.testing.launchFragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.lifecycleScope
import androidx.test.ext.junit.runners.AndroidJUnit4
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.junit.Test
import org.junit.runner.RunWith
import pers.shawxingkwok.mvb.android.mvbScope
import java.util.concurrent.CopyOnWriteArrayList

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
internal class Scope {

@Test
fun useAppContext() {
launchFragment<MyFragment>()
}

class MyViewModel : ViewModel(){}

class MyFragment : Fragment(){
val scopes = CopyOnWriteArrayList<CoroutineScope>()

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
repeat(10){
lifecycleScope.launch(Dispatchers.Default) {
scopes += mvbScope
}
}
}

override fun onDestroy() {
super.onDestroy()
assert(scopes.size == 10)
scopes.single()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package pers.shawxingkwok.mvb.android

import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import java.util.concurrent.ConcurrentHashMap

internal class MVBViewModel(val state: SavedStateHandle) : ViewModel() {
// viewModelScope is not thread-safe.
val scope by lazy{ viewModelScope }

// keeps data from `rmb`
val map = ConcurrentHashMap<String, Container>()
}
3 changes: 2 additions & 1 deletion api/src/main/java/pers/shawxingkwok/mvb/android/mvbScope.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package pers.shawxingkwok.mvb.android

import androidx.lifecycle.ViewModelStoreOwner
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.CoroutineScope

/**
* See [doc](https://shawxingkwok.github.io/ITWorks/docs/multiplatform/mvb/android/#mvbscope).
*/
public val ViewModelStoreOwner.mvbScope: CoroutineScope get() = getMVBVm().scope
public val ViewModelStoreOwner.mvbScope: CoroutineScope get() = getMVBVm().viewModelScope
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
7
9
0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified demo/build/kotlin/compileDebugKotlin/cacheable/last-build.bin
Binary file not shown.
Binary file modified demo/build/kotlin/compileDebugKotlin/local-state/build-history.bin
Binary file not shown.
Loading

0 comments on commit 3e760af

Please sign in to comment.