mirror of
https://github.com/divkit/divkit.git
synced 2026-06-06 20:07:59 +00:00
Subscribe to var changes before invoke observer
This commit is contained in:
+1
-1
@@ -97,8 +97,8 @@ internal class VariableController {
|
||||
}
|
||||
|
||||
private fun onVariableDeclared(variable: Variable) {
|
||||
notifyVariableChanged(variable)
|
||||
variable.addObserver(notifyVariableChangedCallback)
|
||||
notifyVariableChanged(variable)
|
||||
}
|
||||
|
||||
fun getMutableVariable(name: String): Variable? {
|
||||
|
||||
+15
@@ -74,6 +74,21 @@ class VariableControllerTest {
|
||||
Assert.assertEquals("non-initialized", lastValue)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `variable changed inside declaration callback`() {
|
||||
val variable = Variable.StringVariable("late_init_variable", "declared_value")
|
||||
var counter = 0
|
||||
subscribe(variable.name) {
|
||||
if (counter < 5) {
|
||||
counter++
|
||||
variable.set("new_value_$counter")
|
||||
}
|
||||
}
|
||||
|
||||
declareVariable(variable)
|
||||
Assert.assertEquals(5, counter)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `null returned when no variable specified`() {
|
||||
Assert.assertNull(variableController.getMutableVariable("unknown_variable"))
|
||||
|
||||
Reference in New Issue
Block a user