codeforamerica/transitmix — pull request #114 by samhashemi (2014-06-16 02:52:08+00:00)
Title: Refactor views & controllers

This pull request is a first attempt at cleaning up the front-end code. Specifically:

- Introduces two new view classes, `BaseView` and `CollectionView`. Inspired by [LayoutManager](https://github.com/tbranyen/backbone.layoutmanager), these allow for easier rendering of subviews and collections. I've updated the various view classes to adopt these conventions.

- Add an intermediary between routers and views: `Controllers`. Controllers are simple classes that listen to namespaced events on `app.events` and handle app-level logic. E.g. instead of creating lines and updating the router, views can now just call `app.events.trigger('map:newLine')`. Based on ideas from [Marionette](http://marionettejs.com/).

I'm not totally happy with the event-driven controllers concept, but it seems to be the standard in the backbone world.

@dget This is a big change, what do you think? Maybe we can talk through it this week.

Some future possible improvements and refactoring:
- Organize code by controller, probably under a `components` folder
- Add some flavor of [computed properties](https://coderwall.com/p/enlu1a) so we don't have serialize the calculations everywhere.
- Drop `stickit.js` and the bindings field. We don't do two-way bindings that often.
- Possibly sub in handlebars for underscore templates.