|
@@ -3161,6 +3161,15 @@ class MixinState(State, mixin=True):
|
|
num: int = 0
|
|
num: int = 0
|
|
_backend: int = 0
|
|
_backend: int = 0
|
|
|
|
|
|
|
|
+ @rx.var(cache=True)
|
|
|
|
+ def computed(self) -> str:
|
|
|
|
+ """A computed var on mixin state.
|
|
|
|
+
|
|
|
|
+ Returns:
|
|
|
|
+ A computed value.
|
|
|
|
+ """
|
|
|
|
+ return ""
|
|
|
|
+
|
|
|
|
|
|
class UsesMixinState(MixinState, State):
|
|
class UsesMixinState(MixinState, State):
|
|
"""A state that uses the mixin state."""
|
|
"""A state that uses the mixin state."""
|
|
@@ -3168,8 +3177,26 @@ class UsesMixinState(MixinState, State):
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
+class ChildUsesMixinState(UsesMixinState):
|
|
|
|
+ """A child state that uses the mixin state."""
|
|
|
|
+
|
|
|
|
+ pass
|
|
|
|
+
|
|
|
|
+
|
|
def test_mixin_state() -> None:
|
|
def test_mixin_state() -> None:
|
|
"""Test that a mixin state works correctly."""
|
|
"""Test that a mixin state works correctly."""
|
|
assert "num" in UsesMixinState.base_vars
|
|
assert "num" in UsesMixinState.base_vars
|
|
assert "num" in UsesMixinState.vars
|
|
assert "num" in UsesMixinState.vars
|
|
assert UsesMixinState.backend_vars == {"_backend": 0}
|
|
assert UsesMixinState.backend_vars == {"_backend": 0}
|
|
|
|
+
|
|
|
|
+ assert "computed" in UsesMixinState.computed_vars
|
|
|
|
+ assert "computed" in UsesMixinState.vars
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+def test_child_mixin_state() -> None:
|
|
|
|
+ """Test that mixin vars are only applied to the highest state in the hierarchy."""
|
|
|
|
+ assert "num" in ChildUsesMixinState.inherited_vars
|
|
|
|
+ assert "num" not in ChildUsesMixinState.base_vars
|
|
|
|
+
|
|
|
|
+ assert "computed" in ChildUsesMixinState.inherited_vars
|
|
|
|
+ assert "computed" not in ChildUsesMixinState.computed_vars
|