@@ -96,7 +96,8 @@ public open class BaseReactiveState<E : ErrorEvents>(final override val scope: C
96
96
* }
97
97
* ```
98
98
*/
99
- public fun <E : ErrorEvents , P : ReactiveState <out E >, RS : ReactiveState <E >> P.childReactiveState (
99
+ private fun <E : ErrorEvents , P : ReactiveState <* >, RS : ReactiveState <E >> P.childReactiveStateBase (
100
+ eventHandler : suspend (child: RS ) -> Unit ,
100
101
block : () -> RS ,
101
102
): ReadOnlyProperty <Any ?, RS > {
102
103
val child = block()
@@ -106,13 +107,34 @@ public fun <E : ErrorEvents, P : ReactiveState<out E>, RS : ReactiveState<E>> P.
106
107
}
107
108
}
108
109
launch(withLoading = null ) {
109
- eventNotifier.emitAll (child.eventNotifier )
110
+ eventHandler (child)
110
111
}
111
112
(this as ? OnReactiveStateAttached )?.onReactiveStateAttached(child)
112
113
(child as ? OnReactiveStateAttachedTo )?.onReactiveStateAttachedTo(this )
113
114
return WrapperProperty (child)
114
115
}
115
116
117
+ /* *
118
+ * Uses [childReactiveStateBase] and emits events from the child to the parent ReactiveState.
119
+ */
120
+ public fun <E : ErrorEvents , P : ReactiveState <out E >, RS : ReactiveState <E >> P.childReactiveState (
121
+ block : () -> RS ,
122
+ ): ReadOnlyProperty <Any ?, RS > = childReactiveStateBase(
123
+ eventHandler = { child -> eventNotifier.emitAll(child.eventNotifier) },
124
+ block = block,
125
+ )
126
+
127
+ /* *
128
+ * Uses [childReactiveStateBase] and emits events from the child to the given [eventHandler].
129
+ */
130
+ public fun <E : ErrorEvents , P : ReactiveState <* >, RS : ReactiveState <E >> P.childReactiveState (
131
+ eventHandler : E ,
132
+ block : () -> RS ,
133
+ ): ReadOnlyProperty <Any ?, RS > = childReactiveStateBase(
134
+ eventHandler = { child -> child.eventNotifier.handleEvents(eventHandler) },
135
+ block = block,
136
+ )
137
+
116
138
/* * Just wraps an eagerly computed value in a property to allow `val foo by bar` notation. */
117
139
private class WrapperProperty <T >(val data : T ) : ReadOnlyProperty<Any?, T> {
118
140
override fun getValue (thisRef : Any? , property : KProperty <* >): T = data
0 commit comments