diff --git a/reflex/vars/base.py b/reflex/vars/base.py index 9738ed0da..0cd939548 100644 --- a/reflex/vars/base.py +++ b/reflex/vars/base.py @@ -1983,17 +1983,23 @@ class CustomVarOperationReturn(Var[RETURN]): def var_operation_return( js_expression: str, var_type: Type[RETURN] | None = None, + var_data: VarData | None = None, ) -> CustomVarOperationReturn[RETURN]: """Shortcut for creating a CustomVarOperationReturn. Args: js_expression: The JavaScript expression to evaluate. var_type: The type of the var. + var_data: Additional hooks and imports associated with the Var. Returns: The CustomVarOperationReturn. """ - return CustomVarOperationReturn.create(js_expression, var_type) + return CustomVarOperationReturn.create( + js_expression, + var_type, + var_data, + ) @dataclasses.dataclass( diff --git a/reflex/vars/number.py b/reflex/vars/number.py index 31778a25d..38ab15f91 100644 --- a/reflex/vars/number.py +++ b/reflex/vars/number.py @@ -17,7 +17,9 @@ from typing import ( overload, ) +from reflex.constants.base import Dirs from reflex.utils.exceptions import VarTypeError +from reflex.utils.imports import ImportDict, ImportVar from .base import ( CustomVarOperationReturn, @@ -1098,6 +1100,11 @@ class ToBooleanVarOperation(ToOperation, BooleanVar): _default_var_type: ClassVar[Type] = bool +_IS_TRUE_IMPORT: ImportDict = { + f"/{Dirs.STATE_PATH}": [ImportVar(tag="isTrue")], +} + + @var_operation def boolify(value: Var): """Convert the value to a boolean. @@ -1109,8 +1116,9 @@ def boolify(value: Var): The boolean value. """ return var_operation_return( - js_expression=f"Boolean({value})", + js_expression=f"isTrue({value})", var_type=bool, + var_data=VarData(imports=_IS_TRUE_IMPORT), )