jashkenas/backbone — pull request #3146 by FranckErnewein (2014-05-07 17:23:59+00:00)
Title: Switch model/collection on an existing view

If I have a view and would like to display several models successively, the easiest way to do this is to destroy the view then create a new one.
Sometimes I think it could be interesting to keep the same instance.

`View.setElement` is really smart because:
it binds view's method on DOM events based on the `events` options
it allows you to manipulate your view and attach (or move) in the DOM and you don’t have to take care about event binding/unbinding.
it provides an accessor on the view's DOM element which can be overriden for any reason

I think `View.setModel` and `View.setCollection` could be very nice because it could do the same job as `setElement` but on the model/collection.
It binds view's methods on model/collection events based on options ( `modelEvents` / `collectionEvents` ?)
It allows you to create a view without model and attach a model later or switch from a model to another one without removing all listeners.
It provides an accessor on the model/collection which can be overriden for any reason.

for example
````js
//on intialize
//view will start to listen to `initialModel` for change, request and sync events.
var view = new Backbone.View({
modelEvents: {
'change':'render',
'request':'displayLoader',
'sync':'hideLoader'
}
model: initialModel
});
//later, you can replace `initialModel` by `anOtherModel`
// all the events will be unbind on initialModel an bind on anOtherModel automatically
view.setModel(anOtherModel);
//and another time...
view.setModel(lastModel);
````

and of course same concept with collection via `View.setCollection`