reflex 0.5.8a1__py3-none-any.whl → 0.5.9__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of reflex might be problematic. Click here for more details.
- reflex/.templates/web/utils/client_side_routing.js +6 -1
- reflex/.templates/web/utils/state.js +7 -2
- reflex/components/component.py +7 -0
- reflex/components/el/elements/metadata.py +26 -1
- reflex/components/el/elements/metadata.pyi +13 -0
- reflex/experimental/vars/__init__.py +2 -2
- reflex/experimental/vars/base.py +204 -98
- reflex/experimental/vars/function.py +78 -2
- reflex/experimental/vars/number.py +166 -3
- reflex/experimental/vars/object.py +804 -0
- reflex/experimental/vars/sequence.py +946 -221
- reflex/state.py +2 -2
- reflex/utils/format.py +5 -4
- reflex/vars.py +9 -1
- reflex/vars.pyi +3 -2
- {reflex-0.5.8a1.dist-info → reflex-0.5.9.dist-info}/METADATA +1 -1
- {reflex-0.5.8a1.dist-info → reflex-0.5.9.dist-info}/RECORD +20 -19
- {reflex-0.5.8a1.dist-info → reflex-0.5.9.dist-info}/LICENSE +0 -0
- {reflex-0.5.8a1.dist-info → reflex-0.5.9.dist-info}/WHEEL +0 -0
- {reflex-0.5.8a1.dist-info → reflex-0.5.9.dist-info}/entry_points.txt +0 -0
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import dataclasses
|
|
6
|
+
import json
|
|
6
7
|
import sys
|
|
7
8
|
from functools import cached_property
|
|
8
9
|
from typing import Any, Union
|
|
@@ -14,7 +15,7 @@ from reflex.experimental.vars.base import (
|
|
|
14
15
|
from reflex.vars import ImmutableVarData, Var, VarData
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
class NumberVar(ImmutableVar):
|
|
18
|
+
class NumberVar(ImmutableVar[Union[int, float]]):
|
|
18
19
|
"""Base class for immutable number vars."""
|
|
19
20
|
|
|
20
21
|
def __add__(self, other: number_types | boolean_types) -> NumberAddOperation:
|
|
@@ -692,7 +693,7 @@ class NumberTruncOperation(UnaryNumberOperation):
|
|
|
692
693
|
return f"Math.trunc({str(value)})"
|
|
693
694
|
|
|
694
695
|
|
|
695
|
-
class BooleanVar(ImmutableVar):
|
|
696
|
+
class BooleanVar(ImmutableVar[bool]):
|
|
696
697
|
"""Base class for immutable boolean vars."""
|
|
697
698
|
|
|
698
699
|
def __and__(self, other: bool) -> BooleanAndOperation:
|
|
@@ -1253,6 +1254,22 @@ class LiteralBooleanVar(LiteralVar, BooleanVar):
|
|
|
1253
1254
|
)
|
|
1254
1255
|
object.__setattr__(self, "_var_value", _var_value)
|
|
1255
1256
|
|
|
1257
|
+
def __hash__(self) -> int:
|
|
1258
|
+
"""Hash the var.
|
|
1259
|
+
|
|
1260
|
+
Returns:
|
|
1261
|
+
The hash of the var.
|
|
1262
|
+
"""
|
|
1263
|
+
return hash((self.__class__.__name__, self._var_value))
|
|
1264
|
+
|
|
1265
|
+
def json(self) -> str:
|
|
1266
|
+
"""Get the JSON representation of the var.
|
|
1267
|
+
|
|
1268
|
+
Returns:
|
|
1269
|
+
The JSON representation of the var.
|
|
1270
|
+
"""
|
|
1271
|
+
return "true" if self._var_value else "false"
|
|
1272
|
+
|
|
1256
1273
|
|
|
1257
1274
|
@dataclasses.dataclass(
|
|
1258
1275
|
eq=False,
|
|
@@ -1288,8 +1305,154 @@ class LiteralNumberVar(LiteralVar, NumberVar):
|
|
|
1288
1305
|
Returns:
|
|
1289
1306
|
The hash of the var.
|
|
1290
1307
|
"""
|
|
1291
|
-
return hash(self._var_value)
|
|
1308
|
+
return hash((self.__class__.__name__, self._var_value))
|
|
1309
|
+
|
|
1310
|
+
def json(self) -> str:
|
|
1311
|
+
"""Get the JSON representation of the var.
|
|
1312
|
+
|
|
1313
|
+
Returns:
|
|
1314
|
+
The JSON representation of the var.
|
|
1315
|
+
"""
|
|
1316
|
+
return json.dumps(self._var_value)
|
|
1292
1317
|
|
|
1293
1318
|
|
|
1294
1319
|
number_types = Union[NumberVar, LiteralNumberVar, int, float]
|
|
1295
1320
|
boolean_types = Union[BooleanVar, LiteralBooleanVar, bool]
|
|
1321
|
+
|
|
1322
|
+
|
|
1323
|
+
@dataclasses.dataclass(
|
|
1324
|
+
eq=False,
|
|
1325
|
+
frozen=True,
|
|
1326
|
+
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1327
|
+
)
|
|
1328
|
+
class ToNumberVarOperation(NumberVar):
|
|
1329
|
+
"""Base class for immutable number vars that are the result of a number operation."""
|
|
1330
|
+
|
|
1331
|
+
_original_value: Var = dataclasses.field(
|
|
1332
|
+
default_factory=lambda: LiteralNumberVar(0)
|
|
1333
|
+
)
|
|
1334
|
+
|
|
1335
|
+
def __init__(
|
|
1336
|
+
self,
|
|
1337
|
+
_original_value: Var,
|
|
1338
|
+
_var_type: type[int] | type[float] = float,
|
|
1339
|
+
_var_data: VarData | None = None,
|
|
1340
|
+
):
|
|
1341
|
+
"""Initialize the number var.
|
|
1342
|
+
|
|
1343
|
+
Args:
|
|
1344
|
+
_original_value: The original value.
|
|
1345
|
+
_var_type: The type of the Var.
|
|
1346
|
+
_var_data: Additional hooks and imports associated with the Var.
|
|
1347
|
+
"""
|
|
1348
|
+
super(ToNumberVarOperation, self).__init__(
|
|
1349
|
+
_var_name="",
|
|
1350
|
+
_var_type=_var_type,
|
|
1351
|
+
_var_data=ImmutableVarData.merge(_var_data),
|
|
1352
|
+
)
|
|
1353
|
+
object.__setattr__(self, "_original_value", _original_value)
|
|
1354
|
+
object.__delattr__(self, "_var_name")
|
|
1355
|
+
|
|
1356
|
+
@cached_property
|
|
1357
|
+
def _cached_var_name(self) -> str:
|
|
1358
|
+
"""The name of the var.
|
|
1359
|
+
|
|
1360
|
+
Returns:
|
|
1361
|
+
The name of the var.
|
|
1362
|
+
"""
|
|
1363
|
+
return str(self._original_value)
|
|
1364
|
+
|
|
1365
|
+
def __getattr__(self, name: str) -> Any:
|
|
1366
|
+
"""Get an attribute of the var.
|
|
1367
|
+
|
|
1368
|
+
Args:
|
|
1369
|
+
name: The name of the attribute.
|
|
1370
|
+
|
|
1371
|
+
Returns:
|
|
1372
|
+
The attribute value.
|
|
1373
|
+
"""
|
|
1374
|
+
if name == "_var_name":
|
|
1375
|
+
return self._cached_var_name
|
|
1376
|
+
getattr(super(ToNumberVarOperation, self), name)
|
|
1377
|
+
|
|
1378
|
+
@cached_property
|
|
1379
|
+
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1380
|
+
"""Get all VarData associated with the Var.
|
|
1381
|
+
|
|
1382
|
+
Returns:
|
|
1383
|
+
The VarData of the components and all of its children.
|
|
1384
|
+
"""
|
|
1385
|
+
return ImmutableVarData.merge(
|
|
1386
|
+
self._original_value._get_all_var_data(), self._var_data
|
|
1387
|
+
)
|
|
1388
|
+
|
|
1389
|
+
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1390
|
+
return self._cached_get_all_var_data
|
|
1391
|
+
|
|
1392
|
+
|
|
1393
|
+
@dataclasses.dataclass(
|
|
1394
|
+
eq=False,
|
|
1395
|
+
frozen=True,
|
|
1396
|
+
**{"slots": True} if sys.version_info >= (3, 10) else {},
|
|
1397
|
+
)
|
|
1398
|
+
class ToBooleanVarOperation(BooleanVar):
|
|
1399
|
+
"""Base class for immutable boolean vars that are the result of a boolean operation."""
|
|
1400
|
+
|
|
1401
|
+
_original_value: Var = dataclasses.field(
|
|
1402
|
+
default_factory=lambda: LiteralBooleanVar(False)
|
|
1403
|
+
)
|
|
1404
|
+
|
|
1405
|
+
def __init__(
|
|
1406
|
+
self,
|
|
1407
|
+
_original_value: Var,
|
|
1408
|
+
_var_data: VarData | None = None,
|
|
1409
|
+
):
|
|
1410
|
+
"""Initialize the boolean var.
|
|
1411
|
+
|
|
1412
|
+
Args:
|
|
1413
|
+
_original_value: The original value.
|
|
1414
|
+
_var_data: Additional hooks and imports associated with the Var.
|
|
1415
|
+
"""
|
|
1416
|
+
super(ToBooleanVarOperation, self).__init__(
|
|
1417
|
+
_var_name="",
|
|
1418
|
+
_var_type=bool,
|
|
1419
|
+
_var_data=ImmutableVarData.merge(_var_data),
|
|
1420
|
+
)
|
|
1421
|
+
object.__setattr__(self, "_original_value", _original_value)
|
|
1422
|
+
object.__delattr__(self, "_var_name")
|
|
1423
|
+
|
|
1424
|
+
@cached_property
|
|
1425
|
+
def _cached_var_name(self) -> str:
|
|
1426
|
+
"""The name of the var.
|
|
1427
|
+
|
|
1428
|
+
Returns:
|
|
1429
|
+
The name of the var.
|
|
1430
|
+
"""
|
|
1431
|
+
return str(self._original_value)
|
|
1432
|
+
|
|
1433
|
+
def __getattr__(self, name: str) -> Any:
|
|
1434
|
+
"""Get an attribute of the var.
|
|
1435
|
+
|
|
1436
|
+
Args:
|
|
1437
|
+
name: The name of the attribute.
|
|
1438
|
+
|
|
1439
|
+
Returns:
|
|
1440
|
+
The attribute value.
|
|
1441
|
+
"""
|
|
1442
|
+
if name == "_var_name":
|
|
1443
|
+
return self._cached_var_name
|
|
1444
|
+
getattr(super(ToBooleanVarOperation, self), name)
|
|
1445
|
+
|
|
1446
|
+
@cached_property
|
|
1447
|
+
def _cached_get_all_var_data(self) -> ImmutableVarData | None:
|
|
1448
|
+
"""Get all VarData associated with the Var.
|
|
1449
|
+
|
|
1450
|
+
Returns:
|
|
1451
|
+
The VarData of the components and all of its children.
|
|
1452
|
+
"""
|
|
1453
|
+
return ImmutableVarData.merge(
|
|
1454
|
+
self._original_value._get_all_var_data(), self._var_data
|
|
1455
|
+
)
|
|
1456
|
+
|
|
1457
|
+
def _get_all_var_data(self) -> ImmutableVarData | None:
|
|
1458
|
+
return self._cached_get_all_var_data
|