How to Structure and Render Views in Backbone
blog.42floors.com
blog.42floors.com
One of the most frustrating areas of Backbone, as this post talks about, is view management. Rendering and subview management can be thorny issues. Some people look to help from things like Marionette, or ditch Backbone altogether for frameworks that impose convention and take render management away from the developer.
The past several weeks I've been really impressed with React. It is a fantastic, light-weight library for building reusable components and it plays very nicely with Backbone. You can mix together Backbone.Model, .Collection, .Events, but then ditch Backbone.View in favor of React components. It's incredibly fast, thanks to its virtual DOM and diff implementation, and gives you flexibility without needing to worry about render management. Everytime I've refactored a Backbone View into a React component, I think, "Wow, that's it?"
In terms of design patterns, since React components only have parent-child communications, Backbone's existing Events are still a great way to manage communication and convey state between components.
I really encourage everyone to give React a look. It's great.
I realized recently while evaluation angular what it is I really like about backbone, and why I consider it a 'foundational' technology.
It's constrained scope and development history means I'm not actively expecting it to get more complex over time. The releases feel like they are more just 'tightening up' the formula.
https://github.com/greim/Backbone-Subscriptions
...eliminates much of the need to clean up the kinds of event handlers that prevent views from being GC'd. Essentially, it contrives things such that the references preventing views from being GC'd consist in the DOM itself, so that when a node drops out of the DOM, views attached to it are automatically free to be GC'd. Serves our purposes rather well.
It fires methods on transition etc, so you can make it load something when you go to this page, make it change this dialog when it goes to that.
The router was just something that changed the url when the application state changed.