|
@@ -10,6 +10,8 @@ from reflex.testing import AppHarness
|
|
|
|
|
|
def VarOperations():
|
|
def VarOperations():
|
|
"""App with var operations."""
|
|
"""App with var operations."""
|
|
|
|
+ from typing import TypedDict
|
|
|
|
+
|
|
import reflex as rx
|
|
import reflex as rx
|
|
from reflex.vars.base import LiteralVar
|
|
from reflex.vars.base import LiteralVar
|
|
from reflex.vars.sequence import ArrayVar
|
|
from reflex.vars.sequence import ArrayVar
|
|
@@ -17,6 +19,10 @@ def VarOperations():
|
|
class Object(rx.Base):
|
|
class Object(rx.Base):
|
|
name: str = "hello"
|
|
name: str = "hello"
|
|
|
|
|
|
|
|
+ class Person(TypedDict):
|
|
|
|
+ name: str
|
|
|
|
+ age: int
|
|
|
|
+
|
|
class VarOperationState(rx.State):
|
|
class VarOperationState(rx.State):
|
|
int_var1: rx.Field[int] = rx.field(10)
|
|
int_var1: rx.Field[int] = rx.field(10)
|
|
int_var2: rx.Field[int] = rx.field(5)
|
|
int_var2: rx.Field[int] = rx.field(5)
|
|
@@ -34,6 +40,9 @@ def VarOperations():
|
|
dict1: rx.Field[dict[int, int]] = rx.field({1: 2})
|
|
dict1: rx.Field[dict[int, int]] = rx.field({1: 2})
|
|
dict2: rx.Field[dict[int, int]] = rx.field({3: 4})
|
|
dict2: rx.Field[dict[int, int]] = rx.field({3: 4})
|
|
html_str: rx.Field[str] = rx.field("<div>hello</div>")
|
|
html_str: rx.Field[str] = rx.field("<div>hello</div>")
|
|
|
|
+ people: rx.Field[list[Person]] = rx.field(
|
|
|
|
+ [{"name": "Alice", "age": 30}, {"name": "Bob", "age": 25}]
|
|
|
|
+ )
|
|
|
|
|
|
app = rx.App(_state=rx.State)
|
|
app = rx.App(_state=rx.State)
|
|
|
|
|
|
@@ -619,6 +628,15 @@ def VarOperations():
|
|
),
|
|
),
|
|
id="dict_in_foreach3",
|
|
id="dict_in_foreach3",
|
|
),
|
|
),
|
|
|
|
+ rx.box(
|
|
|
|
+ rx.foreach(
|
|
|
|
+ VarOperationState.people,
|
|
|
|
+ lambda person: rx.text.span(
|
|
|
|
+ "Hello " + person["name"], person["age"] + 3
|
|
|
|
+ ),
|
|
|
|
+ ),
|
|
|
|
+ id="typed_dict_in_foreach",
|
|
|
|
+ ),
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
@@ -826,6 +844,7 @@ def test_var_operations(driver, var_operations: AppHarness):
|
|
("dict_in_foreach1", "a1b2"),
|
|
("dict_in_foreach1", "a1b2"),
|
|
("dict_in_foreach2", "12"),
|
|
("dict_in_foreach2", "12"),
|
|
("dict_in_foreach3", "1234"),
|
|
("dict_in_foreach3", "1234"),
|
|
|
|
+ ("typed_dict_in_foreach", "Hello Alice33Hello Bob28"),
|
|
]
|
|
]
|
|
|
|
|
|
for tag, expected in tests:
|
|
for tag, expected in tests:
|