> My question is ..is there any way I can define some common function
that this can be accessed from every design doc? Thanks,
Short answer: no.
Longer answer: Yes, I manage my design docs using couchapp and symlink
common code between design documents in to views/lib/commoncode.js which
can then be require()d in the view function. i.e. something like:
views/lib/commoncode.js:
function api() {
var _afunc = function(a1, a2) {
...
};
var _api = {
afunc: _afunc
};
return(_api);
}
exports.cc = api();
// views/lib/commoncode.js
My view map.js:
function(doc) {
var cc = require('views/lib/commoncode').cc;
if(cc.afunc(doc, 'banana') === true) {
emit(doc._id);
}
}
Notes:
- you cannot require() in the reduce function but there is an open bug
for that feature.
- shared code for views *must* be kept under the views key in the
design document. The content of the views key is hashed to determine if
view indexes need to be rebuilt after a design document update. There
is no problem with other design doc operations doing a require() of code
from views/lib (show/list/update etc).
Regards,
James