-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Leaner/Clearer compiled templates #1189
Comments
I looked into a number of these changes and this route was chosen in most cases over the use of helper functions as this is significantly faster for rendering and the overhead over the wire is minimal with gzip as this is procedurally generate code so it compresses very well. That being said, if someone were to create a pull request that adds a compiler option for this use case if they feel the gzip compression is not sufficient, I'd be open to landing that. |
File size is only one benefit of optimizing this. The main one is simplifying the complexity. I'm finding it difficult to figure out exactly what's going on in order for me to complete compilers that will depend on handlebars-html-parser. |
This is true, but the compiled output of the templates was never intended for human consumption. We are optimizing for the runtime in this case since this is procedurally generated code. If you are writing your own compile to infrastructure, you may want to consider implementing your own version of JavascriptCompiler (you'd need to do the same to implement the helper-based implementation you are proposing) and modify this to fit whatever output you find easiest for you to follow. |
I'd prefer to use the handlebars runtime, but not use |
Then that implies that you'll need to work in the format that the runtime currently uses now. You might be boxing yourself into a particular pattern unnecessarily as the handlebars runtime is highly focus on generating strings as fast as possible and does little to support other object types. HTMLbars as an example only uses the parse, to my knowledge. |
The compiled Handlebars templates appear to use callbacks that return the block-level contents. They wouldn't have to return strings, but could return vDOM/similar objects. But all of the conditions to run functions could be hidden away, making my job more humanly possible. As far as passing HTML as expression parameters, I think that wouldn't be necessary in a good app design with concerns separated. I don't want an HTML parser (or even a hacked regex one) in my runtimes. |
If you want to submit pull requests to help support your use case, we would be glad to consider them, but there is a bit of a bar to be passed as we don't want to degrade performance and additions to the client runtime require breaking changes, so we may be limited in when we can land them. |
How are It's my understanding that: {{#if path1}}
a
{{else if path2}}
b
{{else}}
c
{{/if}} …is parsed as: {{#if path1}}
a
{{else}}
{{#if path2}}
b
{{else}}
c
{{/if}}
{{/if}} |
Is effectively syntactic sugar for this:
Re: what the output looks like,
|
These appears to be possible, then: {{#unless foo}}
{{else if bar}}
{{else}}
{{/unless}} {{#helper foo}}
{{else if bar}}
{{else}}
{{/helper}} Correct? |
Yes. On Sat, Apr 16, 2016 at 4:20 PM Steven Vachon [email protected]
|
Wouldn't this conflict with a view model require("handlebars").compile("{{#if var}} foo {{else}} baz {{/if}}")({else:"bar", var:true});
// " foo " I might've expected the above to produce
|
Users can reference the variable else with [else]. Both of these behaviors
|
Back in the early days I wasn't writing a custom handlebars compiler 😉 Is there a name to describe the special function of Edit: |
@kpdecker regarding PRs that might degrade performance; is it really a concern when the tradeoff is new uses for Handlebars? I think the degradation would be marginal. |
Currently, this:
compiles to:
There is some, in my opinion, unnecessary redundancies in there. Could they not be moved to more descriptive functions such as
maybeCallHelper()
?The text was updated successfully, but these errors were encountered: