Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF-2296] Rename recursive functions #2999

Merged
merged 23 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{% import 'web/pages/utils.js.jinja2' as utils %}

export function {{tag_name}} () {
{% for hook in component.get_hooks_internal() %}
{% for hook in component._get_all_hooks_internal() %}
{{ hook }}
{% endfor %}

{% for hook in memo_trigger_hooks %}
{{ hook }}
{% endfor %}

{% for hook in component.get_hooks() %}
{% for hook in component._get_all_hooks() %}
{{ hook }}
{% endfor %}

Expand Down
14 changes: 7 additions & 7 deletions reflex/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def get_frontend_packages(self, imports: Dict[str, set[ImportVar]]):

def _app_root(self, app_wrappers: dict[tuple[int, str], Component]) -> Component:
for component in tuple(app_wrappers.values()):
app_wrappers.update(component.get_app_wrap_components())
app_wrappers.update(component._get_all_app_wrap_components())
order = sorted(app_wrappers, key=lambda k: k[0], reverse=True)
root = parent = copy.deepcopy(app_wrappers[order[0]])
for key in order[1:]:
Expand Down Expand Up @@ -799,18 +799,18 @@ def compile_(self):

for _route, component in self.pages.items():
# Merge the component style with the app style.
component.add_style(self.style)
component._add_style_recursive(self.style)

component.apply_theme(self.theme)

# Add component.get_imports() to all_imports.
all_imports.update(component.get_imports())
# Add component._get_all_imports() to all_imports.
all_imports.update(component._get_all_imports())

# Add the app wrappers from this component.
app_wrappers.update(component.get_app_wrap_components())
app_wrappers.update(component._get_all_app_wrap_components())

# Add the custom components from the page to the set.
custom_components |= component.get_custom_components()
custom_components |= component._get_all_custom_components()

progress.advance(task)

Expand Down Expand Up @@ -932,7 +932,7 @@ def _submit_work(fn, *args, **kwargs):
all_imports.update(custom_components_imports)

# Get imports from AppWrap components.
all_imports.update(app_root.get_imports())
all_imports.update(app_root._get_all_imports())

progress.advance(task)

Expand Down
20 changes: 10 additions & 10 deletions reflex/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def _compile_document_root(root: Component) -> str:
The compiled document root.
"""
return templates.DOCUMENT_ROOT.render(
imports=utils.compile_imports(root.get_imports()),
imports=utils.compile_imports(root._get_all_imports()),
document=root.render(),
)

Expand All @@ -48,9 +48,9 @@ def _compile_app(app_root: Component) -> str:
The compiled app.
"""
return templates.APP_ROOT.render(
imports=utils.compile_imports(app_root.get_imports()),
custom_codes=app_root.get_custom_code(),
hooks={**app_root.get_hooks_internal(), **app_root.get_hooks()},
imports=utils.compile_imports(app_root._get_all_imports()),
custom_codes=app_root._get_all_custom_code(),
hooks={**app_root._get_all_hooks_internal(), **app_root._get_all_hooks()},
render=app_root.render(),
)

Expand Down Expand Up @@ -109,17 +109,17 @@ def _compile_page(
Returns:
The compiled component.
"""
imports = component.get_imports()
imports = component._get_all_imports()
imports = utils.compile_imports(imports)

# Compile the code to render the component.
kwargs = {"state_name": state.get_name()} if state else {}

return templates.PAGE.render(
imports=imports,
dynamic_imports=component.get_dynamic_imports(),
custom_codes=component.get_custom_code(),
hooks={**component.get_hooks_internal(), **component.get_hooks()},
dynamic_imports=component._get_all_dynamic_imports(),
custom_codes=component._get_all_custom_code(),
hooks={**component._get_all_hooks_internal(), **component._get_all_hooks()},
render=component.render(),
**kwargs,
)
Expand Down Expand Up @@ -264,9 +264,9 @@ def get_shared_components_recursive(component: BaseComponent):
component.rendered_as_shared = False

rendered_components.update(
{code: None for code in component.get_custom_code()},
{code: None for code in component._get_all_custom_code()},
)
all_import_dicts.append(component.get_imports())
all_import_dicts.append(component._get_all_imports())

# Indicate that this component now imports from the shared file.
component.rendered_as_shared = True
Expand Down
6 changes: 3 additions & 3 deletions reflex/compiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def compile_custom_component(
# Get the imports.
imports = {
lib: fields
for lib, fields in render.get_imports().items()
for lib, fields in render._get_all_imports().items()
if lib != component.library
}

Expand All @@ -265,8 +265,8 @@ def compile_custom_component(
"name": component.tag,
"props": props,
"render": render.render(),
"hooks": {**render.get_hooks_internal(), **render.get_hooks()},
"custom_code": render.get_custom_code(),
"hooks": {**render._get_all_hooks_internal(), **render._get_all_hooks()},
"custom_code": render._get_all_custom_code(),
},
imports,
)
Expand Down
3 changes: 2 additions & 1 deletion reflex/components/chakra/forms/pininput.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""A pin input component."""

from __future__ import annotations

from typing import Any, Optional, Union
Expand Down Expand Up @@ -71,7 +72,7 @@ def _get_imports(self) -> ImportDict:
range_var = Var.range(0)
return merge_imports(
super()._get_imports(),
PinInputField().get_imports(), # type: ignore
PinInputField()._get_all_imports(), # type: ignore
picklelo marked this conversation as resolved.
Show resolved Hide resolved
range_var._var_data.imports if range_var._var_data is not None else {},
)

Expand Down
Loading
Loading