-
-
Notifications
You must be signed in to change notification settings - Fork 0
Optimization level 2 #11
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
base: feat/ux-icons-draft-2
Are you sure you want to change the base?
Optimization level 2 #11
Conversation
Co-authored-by: Ryan Weaver <[email protected]>
Transform the component('icon') into icon() twig_function To discuss :)
Can you show in a test how this would work? I think I'm not quite following. Does this replace the need for both the |
Twig compilation is done in 3 steps
In broad terms the idea beeing, for a given template:
And to implement the HTML syntax we added a PreLexer that change the template content just before the tokenizer handles it. In this caseTwig template <twig:Ui:Icon name="github" class="foo bar" /> Tokenizer stepThe TwigComponent PreLexer does it jobs and transform the HTML syntax into a {{ component('Ui:Icon', {name: "github", class="foo bar"}) }} Then the original Lexer transform the source of the template into the TokenStream Parser stepThe Parser... transform the TokenStream into a ModuleNode, and call the NodeTraversers. My special NodeVisitor traverse all the template nodes, and when it finds a At this point we works with Node, but let's say the Node looks as if the template contained: {{ ux_icon("github", {class: "foo bar"}) }} CompilerIn the generated Template class, instead of having something like this echo $this->extensions['Symfony\UX\TwigComponent\Twig\ComponentExtension']->render("Icon", ["name" => "user", "class" => "foo bar"]); We have something like this.
-- So what does it change ? It bypass entirely the TwigComponent system. So we win:
And we lose:
For now it works only with the HTMLSyntax with no embed content (the self-closing tags), but we should discuss if we want to allow that anyway.. It works with hard-coded icon name, and i need to check in more dynamic use cases... |
Can we poke Ryan on this too ? I love this idea/feature, but it is not required now, and better not lose time on it if you guys feel it's a bit too "aggressive" (or any other reason) :) |
Ok, from what I'm seeing this could be added (either a generic thing in twig-components) or in ux-icons w/o BC breaks? |
Of course :) With the EventListener it should already be fast ... and (warning: i'm on a mac) I made some tests on my machine, and the slowest part for me seems to be... the cache :| |
d083168
to
f5f30a1
Compare
42b1923
to
fd873c7
Compare
Transform the
component('icon')
intoicon()
twig_functionTo discuss (and test in performance... this one should be big)