goodybag/allanon — pull request #29 by ProCynic (2013-07-11 16:43:42+00:00)
Title: Make all data model instances

95% of the time you can get away without this in favor of static methods. But when you get in trouble is the need for change events on the model itself. In a case where a model is used and passed from layer to layer to layer (or view to view to view), we need an event-emitter that is passed along with the data. The easiest way to do this is through models.

There are a couple of places where I abuse the global event emitter for this. But this is wrong for a number of reasons. Most notably is when a view takes on a different model, it must un-register its previous event handlers and re-register for the new model.

When defining the API wrappers, we can also specify a model class to use for the data. When the response is received, we'll replace each result with an instance of the class specified.