Cymen Vig

Software Craftsman

Day 54: Backbone routers, Backbone collections...

Backbone router

We’re getting closer to the end of the iteration for the internal projects and we need to bring the design changes that Chris is making into the projects. Our pattern up to now has been to have everything in one window with any interaction (editing, creating) taking place in modal dialog boxes. That worked up to a point but now our applications are becoming more complex. So I began to look into Backbone.js Routers and to think about how to refactor our modal approach to one that can do edit/create in modal but navigating a hierarchy like a normal website where the page contents is replaced and the back button works. It turns out to be fairly simple and that is progressing well.

Backbone collections

We started out using Backbone-Relational. The parent-child relation with this looks like:

1
2
parent.get('child')  // get a collection containing the children
child.get('parent')  // get the parent of the child

This works okay however I’m starting to wonder if it would better to have a collection of each model type. So all of the parents would be in one collection and all of the children would be in another collection.