3 ms·
Pretty much. I'm using this pattern in the following way: SomeComponent.prototype.views = { home: { template: '/path/to/template', render: function(
by tbranyen 15y ago
Pretty much. I'm using this pattern in the following way:
SomeComponent.prototype.views = {
home: {
template: '/path/to/template',
render: function(tmpl) {
this.element.html(Mustache.to_html(tmpl, this.data));
}
}
};
I then have SomeComponent inherit the prototype of Component which has a generic render method. When I call the render method on any given component, it will have some logic to figure out which view it is in, then call the render method specific to that view with the correct template, that it fetches the content of under-the-hood.
Having consistent and expected behavior in your code is a huge win.