Khaleel Al-Adhami hace 8 meses
padre
commit
45f5326bdd
Se han modificado 2 ficheros con 16 adiciones y 2 borrados
  1. 7 1
      reflex/vars/base.py
  2. 9 1
      reflex/vars/number.py

+ 7 - 1
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(

+ 9 - 1
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),
     )