Skip to content

Commit

Permalink
update all render to use position
Browse files Browse the repository at this point in the history
  • Loading branch information
Lendemor committed Dec 18, 2024
1 parent 95222e4 commit 7dfb255
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
10 changes: 9 additions & 1 deletion reflex/.templates/jinja/web/pages/_app.js.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ import * as {{library_alias}} from "{{library_path}}";
{% block export %}
function AppWrap({children}) {

{% for hook in hooks %}
{% for hook, data in hooks if data and data.position and data.position == const.hook_position.INTERNAL %}
{{ hook }}
{% endfor %}

{% for hook, data in hooks if not data or (not data.position or data.position == const.hook_position.PRE_TRIGGER) %}
{{ hook }}
{% endfor %}

{% for hook, data in hooks if data and data.position and data.position == const.hook_position.POST_TRIGGER %}
{{ hook }}
{% endfor %}

Expand Down
11 changes: 10 additions & 1 deletion reflex/.templates/jinja/web/pages/custom_component.js.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@
{% endfor %}

export const {{component.name}} = memo(({ {{-component.props|join(", ")-}} }) => {
{% for hook in component.hooks %}
{% for hook, data in component.hooks if data and data.position and data.position == const.hook_position.INTERNAL %}
{{ hook }}
{% endfor %}

{% for hook, data in component.hooks if not data or (not data.position or data.position == const.hook_position.PRE_TRIGGER) %}
{{ hook }}
{% endfor %}

{% for hook, data in component.hooks if data and data.position and data.position == const.hook_position.POST_TRIGGER %}
{{ hook }}
{% endfor %}

return(
{{utils.render(component.render)}}
)
Expand Down
10 changes: 9 additions & 1 deletion reflex/.templates/jinja/web/pages/index.js.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@

{% block export %}
export default function Component() {
{% for hook in hooks %}
{% for hook, data in hooks.items() if data and data.position and data.position == const.hook_position.INTERNAL %}
{{ hook }}
{% endfor %}

{% for hook, data in hooks.items() if not data or (not data.position or data.position == const.hook_position.PRE_TRIGGER) %}
{{ hook }}
{% endfor %}

{% for hook, data in hooks.items() if data and data.position and data.position == const.hook_position.POST_TRIGGER %}
{{ hook }}
{% endfor %}

Expand Down
4 changes: 2 additions & 2 deletions reflex/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _compile_app(app_root: Component) -> str:
return templates.APP_ROOT.render(
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()},
hooks=app_root._get_all_hooks(),
window_libraries=window_libraries,
render=app_root.render(),
)
Expand Down Expand Up @@ -149,7 +149,7 @@ def _compile_page(
imports=imports,
dynamic_imports=component._get_all_dynamic_imports(),
custom_codes=component._get_all_custom_code(),
hooks={**component._get_all_hooks_internal(), **component._get_all_hooks()},
hooks=component._get_all_hooks(),
render=component.render(),
**kwargs,
)
Expand Down
2 changes: 1 addition & 1 deletion reflex/compiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def compile_custom_component(
"name": component.tag,
"props": props,
"render": render.render(),
"hooks": {**render._get_all_hooks_internal(), **render._get_all_hooks()},
"hooks": {**render._get_all_hooks()},
"custom_code": render._get_all_custom_code(),
},
imports,
Expand Down
2 changes: 1 addition & 1 deletion reflex/components/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -1595,7 +1595,7 @@ def _get_all_hooks(self) -> dict[str, VarData | None]:
code = {}

# Add the internal hooks for this component.
code.update(self._get_all_hooks_internal())
code.update(self._get_hooks_internal())

# Add the hook code for this component.
hooks = self._get_hooks()
Expand Down

0 comments on commit 7dfb255

Please sign in to comment.