Skip to content

Commit

Permalink
remove even more cond and match
Browse files Browse the repository at this point in the history
  • Loading branch information
adhami3310 committed Jan 18, 2025
1 parent db89a71 commit b10f6e8
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 98 deletions.
2 changes: 0 additions & 2 deletions reflex/.templates/jinja/web/pages/utils.js.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
{{- component }}
{%- elif "iterable" in component %}
{{- render_iterable_tag(component) }}
{%- elif "cond" in component %}
{{- render_condition_tag(component) }}
{%- elif component.children|length %}
{{- render_tag(component) }}
{%- else %}
Expand Down
28 changes: 0 additions & 28 deletions reflex/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
cached_property_no_lock,
)
from reflex.vars.function import ArgsFunctionOperation, FunctionStringVar
from reflex.vars.number import ternary_operation
from reflex.vars.object import ObjectVar
from reflex.vars.sequence import LiteralArrayVar

Expand Down Expand Up @@ -2430,33 +2429,6 @@ def render_dict_to_var(tag: dict | Component | str, imported_names: set[str]) ->
func,
)

if tag["name"] == "match":
element = tag["cond"]

conditionals = tag["default"]

for case in tag["match_cases"][::-1]:
condition = case[0].to_string() == element.to_string()
for pattern in case[1:-1]:
condition = condition | (pattern.to_string() == element.to_string())

conditionals = ternary_operation(
condition,
case[-1],
conditionals,
)

return conditionals

if "cond" in tag:
return ternary_operation(
tag["cond"],
render_dict_to_var(tag["true_value"], imported_names),
render_dict_to_var(tag["false_value"], imported_names)
if tag["false_value"] is not None
else Var.create(None),
)

props = {}

special_props = []
Expand Down
2 changes: 0 additions & 2 deletions reflex/components/tags/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Representations for React tags."""

from .cond_tag import CondTag
from .iter_tag import IterTag
from .match_tag import MatchTag
from .tag import Tag
21 changes: 0 additions & 21 deletions reflex/components/tags/cond_tag.py

This file was deleted.

21 changes: 0 additions & 21 deletions reflex/components/tags/match_tag.py

This file was deleted.

25 changes: 1 addition & 24 deletions tests/units/components/test_tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from reflex.components.tags import CondTag, Tag, tagless
from reflex.components.tags import Tag, tagless
from reflex.vars.base import LiteralVar, Var


Expand Down Expand Up @@ -105,29 +105,6 @@ def test_format_tag(tag: Tag, expected: Dict):
assert prop_value.equals(LiteralVar.create(expected["props"][prop]))


def test_format_cond_tag():
"""Test that the cond tag dict is correct."""
tag = CondTag(
true_value=dict(Tag(name="h1", contents="True content")),
false_value=dict(Tag(name="h2", contents="False content")),
cond=Var(_js_expr="logged_in", _var_type=bool),
)
tag_dict = dict(tag)
cond, true_value, false_value = (
tag_dict["cond"],
tag_dict["true_value"],
tag_dict["false_value"],
)
assert cond._js_expr == "logged_in"
assert cond._var_type is bool

assert true_value["name"] == "h1"
assert true_value["contents"] == "True content"

assert false_value["name"] == "h2"
assert false_value["contents"] == "False content"


def test_tagless_string_representation():
"""Test that the string representation of a tagless is correct."""
tag = tagless.Tagless(contents="Hello world")
Expand Down

0 comments on commit b10f6e8

Please sign in to comment.