So, Backbone uses Underscore templates, which I never really used much because I'm such a huge Mustache fan. Anyway, like I said in the last post I've been using Ractive for templating a good deal for work, so I've been thinking about what a template might look like if it were in a framework that I wrote.
I sort of dabbled with this before… about three years ago with a jQuery plugin called jQuery.grab. The idea is, jQuery reads your grab template creates all the elements and wraps select elements in a jQuery object and automatically makes them properties of a given class (constructor object).
So jQuery.grab isn't really a template system but it enables views to be created and have relevant elements selected and wrapped in jQuery objects – which is cool and at the very least makes it so you don't have a million selectors in your code.
So the extension of this is templates that can be bound to the type of object mentioned in the previous post. Additional, these templates should be smart and do as little dome manipulation as possible. Once an element gets created, it gets updated instead of recreated and for collections nodes should be appended if possible or smartly selected and removed.
Anyway, I've been heavily using Backbone along with Ractive (for templating) these days. And, well, it got me thinking of how I would like this stuff to work if I were to write my own framework. I know I may not use it if I write it, but just like Zapp, it could be interesting to think about again.
So, that's pretty interesting, and if you JSON.stringify() the object, all the functions get removed which is nice if you need to pass the new JSON off to the server or something.
See the Pen Spinners by Zevan Rosser (@ZevanRosser) on CodePen.