Hi there,
I´ve used handlebars for quite some time now in various combinations (with Backbone, Ampersand, in Node, etc.) & thought that I might should give htmlbars a spin, by upgrading a tiny ampersand demo application with already existing handlebars templates.
And after some hard time wiring all the pieces together I actually got it running, even with precompiled templates on the server. Everything works as expected, the string concat monster is gone & the pure DOM beast is unleashed.
What does not work as expected, is the data binding. I first thought that you would get this with htmlbars for free & tried this naive approach (hoping for some magic to kick in):
var data = {test: 'foo'};
var output = document.getElementById('output');
var DOMHelper = requireModule('dom-helper').default;
var runtime = requireModule('htmlbars-runtime');
var hooks = runtime.hooks;
var helpers = runtime.helpers;
var env = { dom: new DOMHelper(), hooks: hooks, helpers: helpers };
var dom = template.render(data, env, output);
output.appendChild(dom);
setInterval(function () {
data.test = (data.test === 'foo' ? 'bar' : 'foo');
}, 2000);
The initial render happened, but none of the updates to the data object made it to my screen.
Then after watching a video (from EmberConf I guess), I learned that the data binding stuff lives in
bound-templates.js; I first tried to install it via npm, but it seems that it is not published yet. I eventually got it running in my demo page, but without any effect (and it actually forced me to load the htmlbars-compiler on that page, which I do not want, because precompiling FTW).
So, basically my question is, am I missing something really obvious here?
Is the data binding component really not a part of htmlbars?
If so, is using bound-templates the right way to go?
If so, I would really appreciate an example.
Thank you in advance.
Cheers
Sebastian