Skip to content

Commit

Permalink
Use old serializer system in LiteralVar (#3875)
Browse files Browse the repository at this point in the history
* use serializer system

* add checks for unsupported operands

* and and or are now supported

* format

* remove unnecessary call to JSON

* put base before rest

* fix failing testcase

* add hinting to get static analysis to complain

* damn

* big changes

* get typeguard from extensions

* please darglint

* dangit darglint

* remove one from vars

* add without data and use it in plotly

* DARGLINT

* change format for special props

* add pyi

* delete instances of Var.create

* modify client state to work

* fixed so much

* remove every Var.create

* delete all basevar stuff

* checkpoint

* fix pyi

* get older python to work

* dangit darglint

* add simple fix to last failing testcase

* remove var name unwrapped and put client state on immutable var

* fix older python

* fox event issues

* change forms pyi

* make test less strict

* use rx state directly

* add typeignore to page_id

* implement foreach

* delete .web states folder silly

* update reflex chakra

* fix issue when on mount or on unmount is not set

* nuke Var

* run pyi

* import immutablevar in critical location

* delete unwrap vars

* bring back array ref

* fix style props in app

* /health endpoint for K8 Liveness and Readiness probes (#3855)

* Added API Endpoint

* Added API Endpoint

* Added Unit Tests

* Added Unit Tests

* main

* Apply suggestions from Code Review

* Fix Ruff Formatting

* Update Socket Events

* Async Functions

* Update find_replace (#3886)

* [REF-3592]Promote `rx.progress` from radix themes (#3878)

* Promote `rx.progress` from radix themes

* fix pyi

* add warning when accessing `rx._x.progress`

* Use correct flexgen backend URL (#3891)

* Remove demo template (#3888)

* gitignore .web (#3885)

* update overflowY in AUTO_HEIGHT_JS from hidden to scroll (#3882)

* Retain mutability inside `async with self` block (#3884)

When emitting a state update, restore `_self_mutable` to the value it had
previously so that `yield` in the middle of `async with self` does not result
in an immutable StateProxy.

Fix #3869

* Include child imports in markdown component_map (#3883)

If a component in the markdown component_map contains children components, use
`_get_all_imports` to recursively enumerate them.

Fix #3880

* [REF-3570] Remove deprecated REDIS_URL syntax (#3892)

* mixin computed vars should only be applied to highest level state (#3833)

* improve state hierarchy validation, drop old testing special case (#3894)

* fix var dependency dicts (#3842)

* Adding array to array pluck operation. (#3868)

* fix initial state without cv fallback (#3670)

* add fragment to foreach (#3877)

* Update docker-example (#3324)

* /health endpoint for K8 Liveness and Readiness probes (#3855)

* Added API Endpoint

* Added API Endpoint

* Added Unit Tests

* Added Unit Tests

* main

* Apply suggestions from Code Review

* Fix Ruff Formatting

* Update Socket Events

* Async Functions

* /health endpoint for K8 Liveness and Readiness probes (#3855)

* Added API Endpoint

* Added API Endpoint

* Added Unit Tests

* Added Unit Tests

* main

* Apply suggestions from Code Review

* Fix Ruff Formatting

* Update Socket Events

* Async Functions

* Merge branch 'main' into use-old-serializer-in-literalvar

* [REF-3570] Remove deprecated REDIS_URL syntax (#3892)

* /health endpoint for K8 Liveness and Readiness probes (#3855)

* Added API Endpoint

* Added API Endpoint

* Added Unit Tests

* Added Unit Tests

* main

* Apply suggestions from Code Review

* Fix Ruff Formatting

* Update Socket Events

* Async Functions

* [REF-3570] Remove deprecated REDIS_URL syntax (#3892)

* remove extra var

Co-authored-by: Masen Furer <m_github@0x26.net>

* resolve typo

* write better doc for var.create

* return var value when we know it's literal var

* fix unit test

* less bloat for ToOperations

* simplify ImmutableComputedVar.__get__ (#3902)

* simplify ImmutableComputedVar.__get__

* ruff it

---------

Co-authored-by: Samarth Bhadane <samarthbhadane119@gmail.com>
Co-authored-by: Elijah Ahianyo <elijahahianyo@gmail.com>
Co-authored-by: Masen Furer <m_github@0x26.net>
Co-authored-by: benedikt-bartscher <31854409+benedikt-bartscher@users.noreply.github.com>
Co-authored-by: Vishnu Deva <vishnu.deva12@gmail.com>
Co-authored-by: abulvenz <a.eismann@senbax.de>
  • Loading branch information
7 people authored Sep 10, 2024
1 parent fb721e1 commit a5c73ad
Show file tree
Hide file tree
Showing 182 changed files with 13,597 additions and 11,316 deletions.
5 changes: 2 additions & 3 deletions integration/test_dynamic_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def DynamicRoute():

class DynamicState(rx.State):
order: List[str] = []
page_id: str = ""

def on_load(self):
self.order.append(f"{self.router.page.path}-{self.page_id or 'no page id'}")
Expand All @@ -47,7 +46,7 @@ def index():
is_read_only=True,
id="token",
),
rc.input(value=DynamicState.page_id, is_read_only=True, id="page_id"),
rc.input(value=rx.State.page_id, is_read_only=True, id="page_id"), # type: ignore
rc.input(
value=DynamicState.router.page.raw_path,
is_read_only=True,
Expand All @@ -74,9 +73,9 @@ def redirect_page():
return rx.fragment(rx.text("redirecting..."))

app = rx.App(state=rx.State)
app.add_page(index)
app.add_page(index, route="/page/[page_id]", on_load=DynamicState.on_load) # type: ignore
app.add_page(index, route="/static/x", on_load=DynamicState.on_load) # type: ignore
app.add_page(index)
app.add_custom_404_page(on_load=DynamicState.on_load) # type: ignore


Expand Down
2 changes: 1 addition & 1 deletion integration/test_tailwind.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def test_tailwind_app(tailwind_app: AppHarness, tailwind_disabled: bool):
assert len(paragraphs) == 3
for p in paragraphs:
assert tailwind_app.poll_for_content(p, exp_not_equal="") == PARAGRAPH_TEXT
assert p.value_of_css_property("font-family") == '"monospace"'
assert p.value_of_css_property("font-family") == "monospace"
if tailwind_disabled:
# expect default color, not "text-red-500" from tailwind utility class
assert p.value_of_css_property("color") not in TEXT_RED_500_COLOR
Expand Down
632 changes: 317 additions & 315 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions reflex/.templates/jinja/web/pages/utils.js.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@
{% macro render_match_tag(component) %}
{
(() => {
switch (JSON.stringify({{ component.cond._var_name_unwrapped }})) {
switch (JSON.stringify({{ component.cond._var_name }})) {
{% for case in component.match_cases %}
{% for condition in case[:-1] %}
case JSON.stringify({{ condition._var_name_unwrapped }}):
case JSON.stringify({{ condition._var_name }}):
{% endfor %}
return {{ case[-1] }};
break;
Expand Down
2 changes: 1 addition & 1 deletion reflex/.templates/jinja/web/utils/theme.js.jinja2
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default {{ theme|json_dumps }}
export default {{ theme }}
9 changes: 4 additions & 5 deletions reflex/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
StatefulComponent,
)
from reflex.config import get_config
from reflex.ivars.base import LiteralVar
from reflex.ivars.base import ImmutableVar, LiteralVar
from reflex.state import BaseState
from reflex.style import SYSTEM_COLOR_MODE
from reflex.utils.exec import is_prod_mode
from reflex.utils.imports import ImportVar
from reflex.utils.prerequisites import get_web_dir
from reflex.vars import Var


def _compile_document_root(root: Component) -> str:
Expand Down Expand Up @@ -58,7 +57,7 @@ def _compile_app(app_root: Component) -> str:
)


def _compile_theme(theme: dict) -> str:
def _compile_theme(theme: str) -> str:
"""Compile the theme.
Args:
Expand Down Expand Up @@ -321,7 +320,7 @@ def _compile_tailwind(
def compile_document_root(
head_components: list[Component],
html_lang: Optional[str] = None,
html_custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
html_custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
) -> tuple[str, str]:
"""Compile the document root.
Expand Down Expand Up @@ -378,7 +377,7 @@ def compile_theme(style: ComponentStyle) -> tuple[str, str]:
theme = utils.create_theme(style)

# Compile the theme.
code = _compile_theme(theme)
code = _compile_theme(str(LiteralVar.create(theme)))
return output_path, code


Expand Down
4 changes: 2 additions & 2 deletions reflex/compiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from typing import Any, Callable, Dict, Optional, Type, Union
from urllib.parse import urlparse

from reflex.ivars.base import ImmutableVar
from reflex.utils.prerequisites import get_web_dir

try:
Expand All @@ -32,7 +33,6 @@
from reflex.style import Style
from reflex.utils import console, format, imports, path_ops
from reflex.utils.imports import ImportVar, ParsedImportDict
from reflex.vars import Var

# To re-export this function.
merge_imports = imports.merge_imports
Expand Down Expand Up @@ -286,7 +286,7 @@ def compile_custom_component(
def create_document_root(
head_components: list[Component] | None = None,
html_lang: Optional[str] = None,
html_custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
html_custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
) -> Component:
"""Create the document root.
Expand Down
44 changes: 27 additions & 17 deletions reflex/components/base/app_wrap.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ from typing import Any, Callable, Dict, Optional, Union, overload

from reflex.components.base.fragment import Fragment
from reflex.event import EventHandler, EventSpec
from reflex.ivars.base import ImmutableVar
from reflex.style import Style
from reflex.vars import Var

class AppWrap(Fragment):
@overload
Expand All @@ -21,41 +21,51 @@ class AppWrap(Fragment):
id: Optional[Any] = None,
class_name: Optional[Any] = None,
autofocus: Optional[bool] = None,
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
on_blur: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_click: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
on_blur: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_click: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_context_menu: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_double_click: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_focus: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mount: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mouse_down: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_enter: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_leave: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_move: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_out: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_over: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_up: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_scroll: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_unmount: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
**props,
) -> "AppWrap":
Expand Down
4 changes: 1 addition & 3 deletions reflex/components/base/bare.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ def create(cls, contents: Any) -> Component:
"""
if isinstance(contents, ImmutableVar):
return cls(contents=contents)
if isinstance(contents, Var):
contents = contents.to(str)
else:
contents = str(contents) if contents is not None else ""
return cls(contents=contents) # type: ignore
Expand All @@ -39,7 +37,7 @@ def _render(self) -> Tag:
return Tagless(contents=f"{{{str(self.contents)}}}")
return Tagless(contents=str(self.contents))

def _get_vars(self, include_children: bool = False) -> Iterator[Var]:
def _get_vars(self, include_children: bool = False) -> Iterator[ImmutableVar]:
"""Walk all Vars used in this component.
Args:
Expand Down
44 changes: 27 additions & 17 deletions reflex/components/base/body.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ from typing import Any, Callable, Dict, Optional, Union, overload

from reflex.components.component import Component
from reflex.event import EventHandler, EventSpec
from reflex.ivars.base import ImmutableVar
from reflex.style import Style
from reflex.vars import Var

class Body(Component):
@overload
Expand All @@ -21,41 +21,51 @@ class Body(Component):
id: Optional[Any] = None,
class_name: Optional[Any] = None,
autofocus: Optional[bool] = None,
custom_attrs: Optional[Dict[str, Union[Var, str]]] = None,
on_blur: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_click: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
custom_attrs: Optional[Dict[str, Union[ImmutableVar, str]]] = None,
on_blur: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_click: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_context_menu: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_double_click: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_focus: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mount: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_focus: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mount: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_mouse_down: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_enter: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_leave: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_move: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_out: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_over: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_mouse_up: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_scroll: Optional[
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
on_scroll: Optional[Union[EventHandler, EventSpec, list, Callable, Var]] = None,
on_unmount: Optional[
Union[EventHandler, EventSpec, list, Callable, Var]
Union[EventHandler, EventSpec, list, Callable, ImmutableVar]
] = None,
**props,
) -> "Body":
Expand Down
Loading

0 comments on commit a5c73ad

Please sign in to comment.