use is true (#3946)
This commit is contained in:
parent
abb884c156
commit
d81faf7dad
@ -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(
|
||||
|
@ -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),
|
||||
)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user