Enhancement proposal: destructuring args declaration #275
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I find doT quite elegant and lean 👍, lovin it.
And I propose the enhancement conveyed in this PR, it seems to be competing with #266 (and #29 for the non-nesting case) to address the wondering raised by #214 (with my +1 to it).
This PR introduces a new
args
templateSettitng, which defines a delimiter ({{@ }}
by default) allowed at the very beginning of a template, to declare interesting variable names out of the singleit
object, then with such a declaration present, the mentioned variables are used without prefix throughout the template. Note that with presence of such a declaration,templateSettings.varname
will be ignored in processing of the template instance, thusit
or another name will NOT be available to the template. Templates without the{{@ }}
declaration will maintain old behaviour intact so it'll be automatically backward compatible.I think the test demonstrates it well enough:
The implementation leverages es6 destructuring to selectively accept arguments from
it
(with default value spec, feel like an extra bonus 😃), I feel it sensible at language level, and shouldn't incur unreasonable performance penalty tho I'm not experienced enough with doT to play with the benchmarks.@epoberezkin @olado @1mike12