feat: add state_explicit_vars config option
This commit is contained in:
parent
c721227a06
commit
9c3bac6157
@ -683,6 +683,9 @@ class Config(Base):
|
||||
# Path to file containing key-values pairs to override in the environment; Dotenv format.
|
||||
env_file: Optional[str] = None
|
||||
|
||||
# Whether to only make rx.Field annotated state attributes base vars
|
||||
state_explicit_vars: bool = False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
"""Initialize the config values.
|
||||
|
||||
|
@ -536,11 +536,17 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
||||
**new_backend_vars,
|
||||
}
|
||||
|
||||
from reflex.vars.base import Field
|
||||
|
||||
# Set the base and computed vars.
|
||||
cls.base_vars = {
|
||||
f.name: get_var_for_field(cls, f)
|
||||
for f in cls.get_fields().values()
|
||||
if f.name not in cls.get_skip_vars()
|
||||
and (
|
||||
not get_config().state_explicit_vars
|
||||
or get_origin(f.outer_type_) is Field
|
||||
)
|
||||
}
|
||||
cls.computed_vars = {
|
||||
v._js_expr: v._replace(merge_var_data=VarData.from_state(cls))
|
||||
|
@ -689,6 +689,12 @@ def is_backend_base_variable(name: str, cls: Type) -> bool:
|
||||
if hint == ClassVar:
|
||||
return False
|
||||
|
||||
from reflex.config import get_config
|
||||
from reflex.vars.base import Field
|
||||
|
||||
if get_config().state_explicit_vars and get_origin(hint) is not Field:
|
||||
return False
|
||||
|
||||
if name in cls.inherited_backend_vars:
|
||||
return False
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user