Correct 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…
Rethinking Backbone.js View Rendering
21–30 of 32 posts
Re: Rethinking Backbone.js View Rendering
#22At tout.com, we were having timing issues with view rendering, for example if the view has a flash element in it and the $el isn't in the dom yet, you can't operate on the flash element in the render function. I summarized our new best practice here: http://tommyhallett.tumblr.com/post/37318050812/avoiding-ren...
Another benefit to this approach is it makes replacing, disposing views, creating stacked views easy ... That is when renderTo tries to insert into a container and determines a view is already in place, it can call dispose or detach on the existing view. Much simpler than Marionette regions or other view management approaches.
Re: Rethinking Backbone.js View Rendering
#23Yes, 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
#24Earlier quoted context omitted.
It can get pretty messy at times.
try CoffeeKup: https://github.com/mauricemach/coffeekup or Teacup: http://goodeggs.github.com/teacup/
And when performance is a concern, you can't beat string interpolation within CoffeeScript heredoc strings.
Re: Rethinking Backbone.js View Rendering
#25Yes, 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…
I frequently do this in my apps - I use Handlebars by default, but fall back on _.template() any time my view's absolutely have to have logic in them.
Since Backbone already depends on Underscore, it's harmless in terms of introduced dependencies.
Re: Rethinking Backbone.js View Rendering
#26At tout.com, we were having timing issues with view rendering, for example if the view has a flash element in it and the $el isn't in the dom yet, you can't operate on the flash element in the render function. I summarized our new best practice here: http://tommyhallett.tumblr.com/post/37318050812/avoiding-ren...
I have a lot of canvas drawing going on in my app (charts) and ran into the same issue. As you point out, appending the element to the DOM before everything is fully rendered can cause all sorts of re-drawing to go on. When that's a concern, I proactively set height/width dimensions on the element before adding it. In cases where that's problematic, I just have the render function of the view either update or remove…
Re: Rethinking Backbone.js View Rendering
#27Re: Rethinking Backbone.js View Rendering
#28Earlier quoted context omitted.
try CoffeeKup: https://github.com/mauricemach/coffeekup or Teacup: http://goodeggs.github.com/teacup/
Try https://github.com/mgutz/funcd . It's straight up CoffeeScript functions patterned after Markaby, Erector. Other CoffeeScript templates we tried did funky things with the context and closures didn't work as expected. And when performance is a concern, you can't beat string interpolation within CoffeeScript heredoc strings.
Re: Rethinking Backbone.js View Rendering
#29Also, Why not let JavaScript inject your model data directly into plain vanilla HTML templates? In other words, don't use any template tags at all. These 2 projects are really piquing my interest.
http://blog.nodejitsu.com/micro-templates-are-dead
https://github.com/leonidas/transparency/wiki/Frequently-Ask...
Side benefit is that you can still pre/hybrid render from the server in whatever language you like.