Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controllers vs. App-level View in Backbone.js

I'm trying to pick up Backbone.js and one of the issues I'm trying to work through is how people use controllers effectively in Backbone.

I noticed that controllers were added later in the framework, and that views have a significant amount of controller logic just because of the way the browser and DOM are set up. Also the TODO list example on Backbone's website is implemented without a controller.

So I'm just unclear on how to use the controller aspect of backbone. If anyone could shed some light on this topic I'd really appreciate it.

Thanks! Matt

like image 893
Matt Avatar asked Feb 06 '11 19:02

Matt


1 Answers

The difference between a Backbone.View and a Backbone.Controller is that the Controller has the routes architecture, and the corresponding Backbone.History() listener, which pays attention to the part of the URL after the hash tag (#).

Fundamentally, this means that a Backbone.Controller provides bookmarkable URLs. Because you can hand-write the hash portion, and bookmark them, the Bookmark.Controller should only refer to objects for which it makes sense to display a GETtable item.

I've written a little tutorial, http://www.elfsternberg.com/2010/12/08/backbonejs-introducing-backbone-store/, a port of the Sammy tutorial of The Backbone Store. If you follow the link to the GitHub repository, you can also get the latest version.

like image 183
Elf Sternberg Avatar answered Oct 20 '22 01:10

Elf Sternberg