1
1
package io.github.solrudev.jetmvi
2
2
3
- import androidx.fragment.app.Fragment
4
3
import androidx.lifecycle.Lifecycle
5
- import androidx.lifecycle.LifecycleOwner
6
4
import androidx.lifecycle.coroutineScope
7
5
import androidx.lifecycle.repeatOnLifecycle
8
6
import kotlinx.coroutines.Job
@@ -12,72 +10,6 @@ import kotlinx.coroutines.flow.launchIn
12
10
import kotlinx.coroutines.flow.onEach
13
11
import kotlinx.coroutines.launch
14
12
15
- /* *
16
- * Launches lifecycle-aware collection of the [Flow] of [JetState] which will re-render view each time new state is
17
- * emitted. It also accounts for [JetView.trackedState].
18
- *
19
- * Binding by using [jetViewModels] (or [activityJetViewModels]) delegate is preferred to manually calling this
20
- * function, because it automatically manages binding lifecycle. Don't use this function together with aforementioned
21
- * delegates to avoid duplicate binding.
22
- *
23
- * **For activity:**
24
- *
25
- * This function must be called in activity's `onCreate()`.
26
- *
27
- * **For fragment with a view:**
28
- *
29
- * If fragment has a view, this function must be called in fragment's `onViewCreated()`.
30
- *
31
- * **For fragment without a view:**
32
- *
33
- * If fragment doesn't have a view, this function must be called in fragment's `onCreate()`.
34
- *
35
- * @param jetView a view to bind UI state flow to, parent [JetView] for [derivedViews].
36
- * @param derivedViews views derived from [jetView]. Created with [derivedView] delegate.
37
- * @return [Job] of the flow collection.
38
- */
39
- public fun <S : JetState , V > Flow<S>.bind (jetView : V , vararg derivedViews : JetView <S >): Job
40
- where V : JetView <S >,
41
- V : LifecycleOwner {
42
- if (jetView is Fragment && jetView.view != null ) {
43
- return bind(jetView, derivedViews, jetView.viewLifecycleOwner.lifecycle)
44
- }
45
- return bind(jetView, derivedViews, jetView.lifecycle)
46
- }
47
-
48
- /* *
49
- * Launches lifecycle-aware collection of the [Flow] of [JetState] which will re-render _only_ derived views each time
50
- * new state is emitted. It also accounts for [JetView.trackedState].
51
- *
52
- * Binding by using [jetViewModels] (or [activityJetViewModels]) delegate is preferred to manually calling this
53
- * function, because it automatically manages binding lifecycle. Don't use this function together with aforementioned
54
- * delegates to avoid duplicate binding.
55
- *
56
- * **For activity:**
57
- *
58
- * This function must be called in activity's `onCreate()`.
59
- *
60
- * **For fragment with a view:**
61
- *
62
- * If fragment has a view, this function must be called in fragment's `onViewCreated()`.
63
- *
64
- * **For fragment without a view:**
65
- *
66
- * If fragment doesn't have a view, this function must be called in fragment's `onCreate()`.
67
- *
68
- * @param parentView parent [JetView].
69
- * @param derivedViews views derived from [parentView]. Created with [derivedView] delegate.
70
- * @return [Job] of the flow collection.
71
- */
72
- public fun <S : JetState , V > Flow<S>.bindDerived (parentView : V , vararg derivedViews : JetView <S >): Job
73
- where V : JetView <S >,
74
- V : LifecycleOwner {
75
- if (parentView is Fragment && parentView.view != null ) {
76
- return bind(parentView, derivedViews, parentView.viewLifecycleOwner.lifecycle, bindParent = false )
77
- }
78
- return bind(parentView, derivedViews, parentView.lifecycle, bindParent = false )
79
- }
80
-
81
13
/* *
82
14
* Launches views rendering of this [JetState] flow with the given [lifecycle].
83
15
*/
0 commit comments