9

The common pattern in Backbone/Spine is to re-render the whole view from scratch when something happens.

But what do you do if you only need to update a small part of it (highlight, select, disable, animate etc)?

It doesn't make any sense to re-render everything as it might screw up the current layout (If the page has been scrolled to a certain point for example).

On the other hand if you update small parts "inline" from the View using something like $('.selected').highlight(), then you would have to duplicate the same logic in the view template and JavaScript code.

So what is the "best practice" in Backbone/Spine to do that?

Mike Vormwald
  • 2,280
  • 22
  • 29
Dmytrii Nagirniak
  • 23,696
  • 13
  • 75
  • 130
  • 1
    Best way is to make a small "partial" views and update then when it need an update. You may even can have a view with just a simple input field, and update it when it changes... May be there are better approach, but I'm using this one in current project without any problems. One problem is that you have a lot of views in this case, but anyway it's better that have a lot of spaghetti-code... actually backbone is nothing more, than good tool for organization code. – Dmitry Polushkin Oct 01 '11 at 20:00

2 Answers2

5

In Spine, use the element pattern: http://spinejs.com/docs/controller_patterns

Community
  • 1
  • 1
Alex MacCaw
  • 984
  • 1
  • 6
  • 19
1

on the backbone side of the house, you'd end up using the same jquery... just wrapped up in a backbone view. i blogged about this, here:

http://lostechies.com/derickbailey/2011/09/26/seo-and-accessibility-with-html5-pushstate-part-2-progressive-enhancement-with-backbone-js/

ignore the pushstate, seo and accessibility language in this case. the progressive enhancement ideas are what you're after

Derick Bailey
  • 72,004
  • 22
  • 206
  • 219