|
@@ -10,7 +10,7 @@ from reflex.constants import IS_HYDRATED, RouteVar
|
|
|
from reflex.event import Event, EventHandler
|
|
|
from reflex.state import State
|
|
|
from reflex.utils import format
|
|
|
-from reflex.vars import BaseVar, ComputedVar
|
|
|
+from reflex.vars import BaseVar, ComputedVar, ReflexDict, ReflexList
|
|
|
|
|
|
|
|
|
class Object(Base):
|
|
@@ -1140,3 +1140,33 @@ def test_backend_method():
|
|
|
bms = BackendMethodState()
|
|
|
bms.handler()
|
|
|
assert bms._be_method()
|
|
|
+
|
|
|
+
|
|
|
+def test_setattr_of_mutable_types(mutable_state):
|
|
|
+ """Test that mutable types are converted to corresponding Reflex wrappers.
|
|
|
+
|
|
|
+ Args:
|
|
|
+ mutable_state: A test state.
|
|
|
+ """
|
|
|
+ array = mutable_state.array
|
|
|
+ hashmap = mutable_state.hashmap
|
|
|
+
|
|
|
+ assert isinstance(array, ReflexList)
|
|
|
+ assert isinstance(array[1], ReflexList)
|
|
|
+ assert isinstance(array[2], ReflexDict)
|
|
|
+
|
|
|
+ assert isinstance(hashmap, ReflexDict)
|
|
|
+ assert isinstance(hashmap["key"], ReflexList)
|
|
|
+ assert isinstance(hashmap["third_key"], ReflexDict)
|
|
|
+
|
|
|
+ mutable_state.reassign_mutables()
|
|
|
+
|
|
|
+ array = mutable_state.array
|
|
|
+ hashmap = mutable_state.hashmap
|
|
|
+ assert isinstance(array, ReflexList)
|
|
|
+ assert isinstance(array[1], ReflexList)
|
|
|
+ assert isinstance(array[2], ReflexDict)
|
|
|
+
|
|
|
+ assert isinstance(hashmap, ReflexDict)
|
|
|
+ assert isinstance(hashmap["mod_key"], ReflexList)
|
|
|
+ assert isinstance(hashmap["mod_third_key"], ReflexDict)
|