use macros for rendering
This commit is contained in:
parent
7dfb25591b
commit
0300f81c3e
@ -1,4 +1,5 @@
|
|||||||
{% extends "web/pages/base_page.js.jinja2" %}
|
{% extends "web/pages/base_page.js.jinja2" %}
|
||||||
|
{% from "web/pages/macros.js.jinja2" import renderHooks %}
|
||||||
|
|
||||||
{% block early_imports %}
|
{% block early_imports %}
|
||||||
import '$/styles/styles.css'
|
import '$/styles/styles.css'
|
||||||
@ -18,18 +19,7 @@ import * as {{library_alias}} from "{{library_path}}";
|
|||||||
|
|
||||||
{% block export %}
|
{% block export %}
|
||||||
function AppWrap({children}) {
|
function AppWrap({children}) {
|
||||||
|
{{ renderHooks(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 %}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
{{utils.render(render, indent_width=0)}}
|
{{utils.render(render, indent_width=0)}}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{% extends "web/pages/base_page.js.jinja2" %}
|
{% extends "web/pages/base_page.js.jinja2" %}
|
||||||
|
{% from "web/pages/macros.js.jinja2" import renderHooks %}
|
||||||
{% block export %}
|
{% block export %}
|
||||||
{% for component in components %}
|
{% for component in components %}
|
||||||
|
|
||||||
@ -8,17 +8,7 @@
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
||||||
export const {{component.name}} = memo(({ {{-component.props|join(", ")-}} }) => {
|
export const {{component.name}} = memo(({ {{-component.props|join(", ")-}} }) => {
|
||||||
{% for hook, data in component.hooks if data and data.position and data.position == const.hook_position.INTERNAL %}
|
{{ renderHooks(component.hooks.items()) }}
|
||||||
{{ 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(
|
return(
|
||||||
{{utils.render(component.render)}}
|
{{utils.render(component.render)}}
|
||||||
|
54
reflex/.templates/jinja/web/pages/macros.js.jinja2
Normal file
54
reflex/.templates/jinja/web/pages/macros.js.jinja2
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
{% macro sortHooks(hooks) %}
|
||||||
|
{% set internal_hooks = [] %}
|
||||||
|
{% set pre_trigger_hooks = [] %}
|
||||||
|
{% set post_trigger_hooks = [] %}
|
||||||
|
|
||||||
|
{% for hook, data in hooks %}
|
||||||
|
{% if data and data.position and data.position == const.hook_position.INTERNAL %}
|
||||||
|
{% set internal_hooks = internal_hooks + [hook] %}
|
||||||
|
{% elif data and data.position and data.position == const.hook_position.POST_TRIGGER %}
|
||||||
|
{% set post_trigger_hooks = post_trigger_hooks+ [hook] %}
|
||||||
|
{% else %}
|
||||||
|
{% set pre_trigger_hooks = pre_trigger_hooks + [hook] %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro renderHooks(hooks) %}
|
||||||
|
{{ sortHooks(hooks) }}
|
||||||
|
|
||||||
|
{# Render the grouped hooks #}
|
||||||
|
{% for hook in internal_hooks %}
|
||||||
|
{{ hook }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for hook in pre_trigger_hooks %}
|
||||||
|
{{ hook }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for hook in post_trigger_hooks %}
|
||||||
|
{{ hook }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endmacro %}
|
||||||
|
|
||||||
|
{% macro renderHooksWithMemo(hooks, memo)%}
|
||||||
|
{{ sortHooks(hooks) }}
|
||||||
|
|
||||||
|
{# Render the grouped hooks #}
|
||||||
|
{% for hook in internal_hooks %}
|
||||||
|
{{ hook }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for hook in pre_trigger_hooks %}
|
||||||
|
{{ hook }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for hook in memo %}
|
||||||
|
{{ hook }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% for hook in post_trigger_hooks %}
|
||||||
|
{{ hook }}
|
||||||
|
{% endfor %}
|
||||||
|
|
||||||
|
{% endmacro %}
|
@ -1,23 +1,9 @@
|
|||||||
{% import 'web/pages/utils.js.jinja2' as utils %}
|
{% import 'web/pages/utils.js.jinja2' as utils %}
|
||||||
|
{% from 'web/pages/macros.js.jinja2' import renderHooksWithMemo %}
|
||||||
{% set all_hooks = component._get_all_hooks().items() %}
|
{% set all_hooks = component._get_all_hooks().items() %}
|
||||||
|
|
||||||
export function {{tag_name}} () {
|
export function {{tag_name}} () {
|
||||||
{% for hook, data in all_hooks if data and data.position and data.position == const.hook_position.INTERNAL %}
|
{{ renderHooksWithMemo(all_hooks, memo_trigger_hooks) }}
|
||||||
{{ hook }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% for hook, data in all_hooks if not data or (not data.position or data.position == const.hook_position.PRE_TRIGGER) %}
|
|
||||||
{{ hook }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% for hook in memo_trigger_hooks %}
|
|
||||||
{{ hook }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% for hook, data in all_hooks if data and data.position and data.position == const.hook_position.POST_TRIGGER %}
|
|
||||||
{{ hook }}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
{{utils.render(component.render(), indent_width=0)}}
|
{{utils.render(component.render(), indent_width=0)}}
|
||||||
|
Loading…
Reference in New Issue
Block a user