Rethinking Backbone.js View Rendering
1–10 of 32 posts
Re: Rethinking Backbone.js View Rendering
#2Re: Rethinking Backbone.js View Rendering
#3Re: Rethinking Backbone.js View Rendering
#4For trivial cases, this could be implemented in the model's 'defaults' function. (by computing the transformed field value in the function and returning a hash) If you forsee the need to update the value of the dynamic field in response to the client updating the model, you can perform the calculation again in the Model's 'validate' function.
Speaking from experience, logic in templates is convenient for trivial use cases, but can be very difficult to maintain once a project grows.
Re: Rethinking Backbone.js View Rendering
#5I summarized our new best practice here: http://tommyhallett.tumblr.com/post/37318050812/avoiding-ren...
Re: Rethinking Backbone.js View Rendering
#6Correct me if I'm wrong, but wouldn't the best place to combine and transform model data be in the model itself? For trivial cases, this could be implemented in the model's 'defaults' function. (by computing the transformed field value in the function and returning a hash) If you forsee the need to update the value of the dynamic field in response to the client updating the model, you can perform the calculation agai…
Agreed, my first thought was that there is no way to actively debug the template logic.
Re: Rethinking Backbone.js View Rendering
#7 account.statusWarning()
document.listOfCollaborators()
photo.similar.first().publicUrl()
... and so on. But by all means, don't use Handlebars to do it. Use a templating engine that allows real logic, and rest easier at night. Handlebars is set up as faux-logicless templating -- A wolf in Mustache.js' clothing. Having to add Handlebars helpers just to be allowed to call a "method" (as shown in the blog post) is pretty silly example of forced indirection, no? Much more straightforward with embedded JavaScript: {{ model.getFullName() }}Re: Rethinking Backbone.js View Rendering
#8Yes, absolutely pass models directly to your views. That's what they're for, after all -- keeping together a handy bunch of methods that can display your data in ways that are terrifically useful for a view to show: account.statusWarning() document.listOfCollaborators() photo.similar.first().publicUrl() ... and so on. But by all means, don't use Handlebars to do it. Use a templating engine that allows real logic, and…
Why oh why would you ever use Handlebars over, say, Underscore's templates which allow actually logic? In my (admittedly limited) experience, both choices are equally as simple when writing simple templates, but Handlebars is a colossal pain in the ass when trying to do something significant.
Re: Rethinking Backbone.js View Rendering
#9Yes, absolutely pass models directly to your views. That's what they're for, after all -- keeping together a handy bunch of methods that can display your data in ways that are terrifically useful for a view to show: account.statusWarning() document.listOfCollaborators() photo.similar.first().publicUrl() ... and so on. But by all means, don't use Handlebars to do it. Use a templating engine that allows real logic, and…
Re: Rethinking Backbone.js View Rendering
#10Yes, absolutely pass models directly to your views. That's what they're for, after all -- keeping together a handy bunch of methods that can display your data in ways that are terrifically useful for a view to show: account.statusWarning() document.listOfCollaborators() photo.similar.first().publicUrl() ... and so on. But by all means, don't use Handlebars to do it. Use a templating engine that allows real logic, and…