What are the differences between Handlebars 1.x and 2.x APIs?

We are currently using Handlebars version 1.3.0, and I would like to know that if anything, we will need to change to be able to upgrade to version 2.x. Since the HandlebarsJS team is committed to semantic version control, I know that there should be some changes, but I do not see them in the README.md list. There are some points listed in the changes in v2.0.0-alpha.N versions , but it’s not clear to me whether it is a complete list (or if a complete list will exist prior to the release of version 2.0.0). Some of the 1.x releases also have "compatibilty notse" sections, but I think they are all inextricable / advanced.

Can someone give an idea of ​​the differences between the APIs or the goals / improvements of the 2.x series?

Compatibility Notes

  • To run the compiler in IE8 and below, a JSON polyfill is required. He recommended using a precompiler instead of starting the compiler in these legacy environments.
  • helperMissing The helper no longer has an argument with an indexed name. The helper name is now available through options.name.
  • The precompiler output has changed, which violates compatibility with previous versions of the runtime and the precompiled output.
  • JavaScriptCompiler.compilerInfo now returns shared objects, not the javascript source.
  • AST changes
    • INTEGER β†’ NUMBER
    • Optional hash parameter PartialNode
    • New type RawBlockNode
  • Data frames now have a _parent field. This is internal but enumerated for performance / compatibility reasons.

Update: from ember.js Blog on 10/16/2014

In addition to the changes noted above:

Lines containing only block statements and spaces are now deleted. This complies with the Mustache specification, but can cause problems with code that expects an empty creature, but otherwise it would not.

+7
compatibility
source share
1 answer

If you look at the changes between v1.3.0 and v2.0.0-alpha.1 Handlebars in accordance with the official release notes , you will see that these were two major changes that would break your patterns during the upgrade.

  • The precompiler output has changed, which means that your precompiled 1.x templates will not be compatible with Runlebars 2.x, and 2.x runtime will not be compatible with old templates. You must update the precompiler, update the runtime, and update all templates.
  • Particles no longer have access to the parent context ( ../ ), but can now accept the hash as an argument and have access to the root context via the @root variable. So look at the partial ones to use ../ and change it to use local data passed to partial as an argument.

So, the main thing that you should pay attention to when upgrading version 2.x of Handlebars. There were some internal changes that affect the helperMissing , JavaScriptCompiler.compilerInfo , update AST and data frames . But all this makes sense only for users who use their own plugs or make some changes at runtime. Other changes were mostly fixes.

+8
source share

All Articles