janmonschke/backbone-couchdb — pull request #46 by allexpert (2012-05-05 09:18:27+00:00)
Title: Apply view/list functions to _changes

Models based on views/lists are insufficient if they return not a list of pure documents and are dynamically listening to changes, since changes can be reported from Couchdb only as plain documents. There were some efforts from Couchdb to adopt the view/list conccept on top of the _changes API:

https://issues.apache.org/jira/browse/COUCHDB-979

but unfortunately there is no sign of progress in that direction for more than a year.

If you base your model on a view/list, you need somehow to transform results returned by _changes query to fir your model. This can readily and naturally be done in Backbone-couchdb, thus the JS application on top of it can operate purely with the view/list based model, regardless of where the data is coming from: a full GET query or an update.

This patch does this by reading the view and optionally the list functions from the couchdb server and applying this to the changes (_db_on_change() callback). If neither view nor list is defined, it works as before.

One more little change is overriding the Backbone db_name parameter, allowing to call several databases from the same JS file.