Monthly Archives: June 2012

Routed Commands for Backbone.js

Here’s a quick fiddle that shows how to route a command between sub-views no matter how they’re nested in the DOM. Basically, when a sub-view is rendered it triggers a subscribe event that’s captured by the application view which then sets a delegate on another sub-view. This other sub-view is the source of the events, e.g. a menu bar.

When the event source sub-view triggers events (e.g. clicking a link), it does so on the delegate. Event names are specified in the HTML using a data-event attribute on the link. Enjoy!

Continue reading