There are a number of functions I want to use across various couchdb view map functions. I am trying to use the commonjs require pattern.

Using the following design doc why does the test1 require statement work whereas the test2 require statement does not seem to work ?

How else can I reuse functions across multiple couchdb views ?

{
    "_id": "_design/app",
    "_rev": "29-876296b1278db067378635a5f3309aa3",
    "views": {
       "test1": {
           "map": "function (doc) {\n  var setting1 = require('views/lib/config').setting1;\n    emit(doc._id, setting1);\n  }"
       },
       "test2": {
           "map": "function (doc) {\n  var fn1 = require('views/lib/sharedFunctions').fn1;\n    emit(doc._id, fn1(doc));\n  }"
       },
       "lib": {
           "config": "exports.setting1 = 'a';exports.setting2 = 42",
           "sharedFunctions":"exports.fn1 = function (doc) {\n   return 'fn1 read doc ' + doc._id;\n }"
       }
    }
}

further info: I am currently using the 'grunt-couchapp' plugin for managing the uploading of my design docs from my project src directories

有帮助吗?

解决方案

Just adding this as the answer so that this question stops appearing unanswered. The OP found that upgrading to 1.3 (from 1.2) fixed the problem.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top