We've recently been discussing a variety of topics on IRC and I wanted to bring back up an idea for super-basic template support.
We've discussed how the existing SC.TemplateView is rather clunky and deprecated since it is no longer maintained. I've been trying to figure out a good way to support some basic template views without a lot of maintenance, change, or frustration; and after some research I've been doing, I wanted to shoot out a semi-formal proposition to get things started.
ECMAScript 6 is the latest JS language definition and is on track to be standardized in early-to-mid 2015. Many browsers are already beginning to support it, and there is a
Traceur library which "transpiles" ES6 code to ES5 code so that it can run on older browsers.
One of my biggest gripes with custom SC views is that you have to do a bunch of ugly string concatenation and use of .fmt() to insert variables into strings. ES6 gives us a much nicer way of doing this with
Template Strings.
Template Strings simply start and end with back ticks (`) and can have variables embedded through string interpolation. Here's a super-quick example:
render: function(context) {
var c = this.get('content'),
styleClass = c.get('styleClass'),
body = c.get('body'),
html = `<div class='${styleClass}'>
${body}
</div>`;
context.push(html);
}
As you can see, this code looks quite a bit cleaner than the normal render() code (at least that I produce) and being that this will be the standard soon, I feel like this would kill 80% of the frustration for a relatively small investment.
I believe the best way to support this would be with a plugin in the new build tools that passes everything off to Traceur as the last step, and I *think* that is all it that we'd need to do.
This would give us the added bonus of being able to try out some of the other ES6 features early if we wanted to.
I'd love to hear people's thoughts on this approach and if it would be a decent first-step.
Thanks!
--
Topher Fangio
Director of Software Development
Pharos Resources
office:
325.216.2908mobile:
325.660.7141