What can I do to share code among views in CouchDB?
Jesse Hallett has some good utility methods, including
fun
As per this blog post, you can add commonjs modules to the map function (but not the reduce function) in views in couchdb 1.1 by having a key called lib in your views object. A lot of popular javascript libraries like underscore.js adhere to the commonjs standard, so you can use them in your views by using require("views/lib/[your module name]").
Say you include underscore.js as "underscore" in the lib object in views, like so:
views: {
lib: {
underscore: "// Underscore.js 1.1.6\n ...
}
...
[ the rest of your views go here]
}
, you can then add the following to your view to get access to the _ module:
var _ = require("views/lib/underscore");
For custom libraries, all you need to do is make anything you want to share in your library a value to the global "exports" object.