@@ -21,6 +21,8 @@ import app.nubrick.nubrick.schema.Property
2121import app.nubrick.nubrick.schema.UIBlock
2222import app.nubrick.nubrick.template.compile
2323import kotlinx.coroutines.Dispatchers
24+ import kotlinx.coroutines.flow.MutableStateFlow
25+ import kotlinx.coroutines.flow.StateFlow
2426import kotlinx.coroutines.withContext
2527import kotlinx.serialization.json.JsonElement
2628
@@ -53,11 +55,10 @@ internal interface Container {
5355 pageProperties : List <Property >? ,
5456 ): JsonElement
5557
58+ val formValuesFlow: StateFlow <Map <String , FormValue >>
5659 fun getFormValues (): Map <String , JsonElement >
5760 fun getFormValue (key : String ): FormValue ?
5861 fun setFormValue (key : String , value : FormValue )
59- fun addFormValueListener (listener : FormValueListener )
60- fun removeFormValueListener (listener : FormValueListener )
6162
6263 fun compileHttpRequest (
6364 req : ApiHttpRequest ,
@@ -118,8 +119,8 @@ internal class ContainerImpl(
118119 ): JsonElement {
119120 val userState by user.state.collectAsStateWithLifecycle()
120121 val userProperties = userState.templateProperties
121- val formValues = formRepository?.formValues? .collectAsStateWithLifecycle()
122- val formData = formValues?.value? .toFormData()
122+ val formValues by formValuesFlow .collectAsStateWithLifecycle()
123+ val formData = formValues.toFormData()
123124 return remember(this , data, pageProperties, userProperties, formData) {
124125 createVariableForTemplate(
125126 data = data,
@@ -132,6 +133,9 @@ internal class ContainerImpl(
132133 }
133134 }
134135
136+ override val formValuesFlow: StateFlow <Map <String , FormValue >> =
137+ formRepository?.formValues ? : MutableStateFlow (emptyMap())
138+
135139 override fun getFormValues (): Map <String , JsonElement > {
136140 return this .formRepository?.getFormData() ? : emptyMap()
137141 }
@@ -144,14 +148,6 @@ internal class ContainerImpl(
144148 this .formRepository?.setValue(key, value)
145149 }
146150
147- override fun addFormValueListener (listener : FormValueListener ) {
148- this .formRepository?.addListener(listener)
149- }
150-
151- override fun removeFormValueListener (listener : FormValueListener ) {
152- this .formRepository?.removeListener(listener)
153- }
154-
155151 override suspend fun sendHttpRequest (
156152 req : ApiHttpRequest ,
157153 variable : JsonElement ,
0 commit comments