update all render to use position

This commit is contained in:
Lendemor 2024-12-18 14:01:56 +01:00
parent 95222e49f3
commit 7dfb25591b
6 changed files with 32 additions and 7 deletions

View File

@ -19,7 +19,15 @@ import * as {{library_alias}} from "{{library_path}}";
{% block export %} {% block export %}
function AppWrap({children}) { 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 }} {{ hook }}
{% endfor %} {% endfor %}

View File

@ -8,9 +8,18 @@
{% endfor %} {% endfor %}
export const {{component.name}} = memo(({ {{-component.props|join(", ")-}} }) => { 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 }} {{ hook }}
{% endfor %} {% 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( return(
{{utils.render(component.render)}} {{utils.render(component.render)}}
) )

View File

@ -8,7 +8,15 @@
{% block export %} {% block export %}
export default function Component() { 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 }} {{ hook }}
{% endfor %} {% endfor %}

View File

@ -75,7 +75,7 @@ def _compile_app(app_root: Component) -> str:
return templates.APP_ROOT.render( return templates.APP_ROOT.render(
imports=utils.compile_imports(app_root._get_all_imports()), imports=utils.compile_imports(app_root._get_all_imports()),
custom_codes=app_root._get_all_custom_code(), 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, window_libraries=window_libraries,
render=app_root.render(), render=app_root.render(),
) )
@ -149,7 +149,7 @@ def _compile_page(
imports=imports, imports=imports,
dynamic_imports=component._get_all_dynamic_imports(), dynamic_imports=component._get_all_dynamic_imports(),
custom_codes=component._get_all_custom_code(), 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(), render=component.render(),
**kwargs, **kwargs,
) )

View File

@ -290,7 +290,7 @@ def compile_custom_component(
"name": component.tag, "name": component.tag,
"props": props, "props": props,
"render": render.render(), "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(), "custom_code": render._get_all_custom_code(),
}, },
imports, imports,

View File

@ -1595,7 +1595,7 @@ class Component(BaseComponent, ABC):
code = {} code = {}
# Add the internal hooks for this component. # 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. # Add the hook code for this component.
hooks = self._get_hooks() hooks = self._get_hooks()