@@ -2,11 +2,6 @@ package com.rickclephas.kmp.observableviewmodel
2
2
3
3
import com.rickclephas.kmp.observableviewmodel.objc.KMPOVMViewModelScopeProtocol
4
4
import kotlinx.coroutines.CoroutineScope
5
- import kotlinx.coroutines.flow.MutableStateFlow
6
- import kotlinx.coroutines.flow.StateFlow
7
- import kotlinx.coroutines.flow.asStateFlow
8
- import kotlinx.coroutines.flow.update
9
- import platform.darwin.NSObject
10
5
11
6
/* *
12
7
* Holds the [CoroutineScope] of a [ViewModel].
@@ -18,56 +13,10 @@ public actual typealias ViewModelScope = KMPOVMViewModelScopeProtocol
18
13
* Creates a new [ViewModelScope] for the provided [coroutineScope].
19
14
*/
20
15
internal actual fun ViewModelScope (coroutineScope : CoroutineScope ): ViewModelScope =
21
- ViewModelScopeImpl (coroutineScope)
16
+ NativeViewModelScope (coroutineScope)
22
17
23
18
/* *
24
19
* Gets the [CoroutineScope] associated with the [ViewModel] of `this` [ViewModelScope].
25
20
*/
26
21
public actual val ViewModelScope .coroutineScope: CoroutineScope
27
- get() = asImpl().coroutineScope
28
-
29
- /* *
30
- * Casts `this` [ViewModelScope] to a [ViewModelScopeImpl].
31
- */
32
- @InternalKMPObservableViewModelApi
33
- public inline fun ViewModelScope.asImpl (): ViewModelScopeImpl = this as ViewModelScopeImpl
34
-
35
- /* *
36
- * Implementation of [ViewModelScope].
37
- * @property coroutineScope The [CoroutineScope] associated with the [ViewModel].
38
- */
39
- @InternalKMPObservableViewModelApi
40
- public class ViewModelScopeImpl internal constructor(
41
- public val coroutineScope : CoroutineScope
42
- ): NSObject(), ViewModelScope {
43
-
44
- private val _subscriptionCount = MutableStateFlow (0 )
45
- /* *
46
- * A [StateFlow] that emits the number of subscribers to the [ViewModel].
47
- */
48
- public val subscriptionCount: StateFlow <Int > = _subscriptionCount .asStateFlow()
49
-
50
- override fun increaseSubscriptionCount () {
51
- _subscriptionCount .update { it + 1 }
52
- }
53
-
54
- override fun decreaseSubscriptionCount () {
55
- _subscriptionCount .update { it - 1 }
56
- }
57
-
58
- private var sendObjectWillChange: (() -> Unit )? = null
59
-
60
- override fun setSendObjectWillChange (sendObjectWillChange : () -> Unit ) {
61
- if (this .sendObjectWillChange != null ) {
62
- throw IllegalStateException (" ViewModel can't be wrapped more than once" )
63
- }
64
- this .sendObjectWillChange = sendObjectWillChange
65
- }
66
-
67
- /* *
68
- * Invokes the object will change listener set by [setSendObjectWillChange].
69
- */
70
- public fun sendObjectWillChange () {
71
- sendObjectWillChange?.invoke()
72
- }
73
- }
22
+ get() = asNative().coroutineScope
0 commit comments