linkedin / dustjs

Asynchronous Javascript templating for the browser and server
http://dustjs.com
MIT License
2.92k stars 478 forks source link

Add `context.tap` #554

Closed sethkinast closed 9 years ago

sethkinast commented 9 years ago

Forcing use of dust.helpers.tap is not great. Something as basic as tapping a dust variable string to resolve its vars should be part of core.

smfoote commented 9 years ago

Here here!

jimmyhchan commented 9 years ago

auto tap? pre-compilation? tapping at all seemed kinda strange and context.get seems like a very similar

sethkinast commented 9 years ago

I think based on #528 there's not going to be a reasonable way to do what's right 100% of the time with an auto tap.

I can at least improve the state of things from this:

// require dustjs-helpers
foo: function(chunk, context, bodies, params) {
  tapped = dust.helpers.tap(params.bar, chunk, context);
}

To this:

foo: function(chunk, context, bodies, params) {
  tapped = context.tap(params.bar);
}
rragan commented 9 years ago

That is such an improvement. Well worthwhile. +1

smfoote commented 9 years ago

Any way we could have a mutative context.tap(params);? I haven't thought through it, but it seems kinda nice.

sethkinast commented 9 years ago

The main problem with mutating is when you want to evaluate the same param at different levels of the stack. See #528.

I've experimented with several models. I liked the idea of transforming params into a magic getter object, but browser support and speed led me to drop that implementation for now.

This doesn't preclude us doing something more powerful in the future; it's simply a QoL improvement.

Some further improvements could be: context.tapAllTheThingsAndGimmeANewObject() context.magicallyConvertAllParamsToGettersThatShadowTheirOriginalProperties()

etc