couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Couchdb Wiki] Update of "CommonJS_Modules" by MaxOgden
Date Wed, 20 Jul 2011 01:45:36 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for change notification.

The "CommonJS_Modules" page has been changed by MaxOgden:
http://wiki.apache.org/couchdb/CommonJS_Modules?action=diff&rev1=5&rev2=6

Comment:
updating to reflect changes in couch v1.1

  ## page was renamed from commonjs_modules
  = CommonJS Modules =
- As of the 0.11 release of CouchDB you can use CommonJS 1.0 modules in your show, list, update,
and validation functions. map and reduce functions '''can NOT''' use modules. This is because
view results are stored in the B-tree, and if the module (which is now external to the view
itself) was updated, CouchDB would not be aware of the changed module, & therefore would
not recompute the view.
+ 
+ As of the 1.1 release of CouchDB you can use CommonJS 1.0 modules in your map, show, list,
update, and validation functions. Reduce functions '''can NOT''' use modules. When using CommonJS
in map function you must place your CommonJS under the views/lib property in your CouchApp
(see below).
  
  {{{#!highlight JavaScript
    {
@@ -18, +19 @@

     shows: {
       simple: "function() {return 'ok'};",
       requirey : "function() { var lib = require('whatever/commonjs/upper'); return lib.testing;
};"
+    },
+    views: {
+      lib: { 
+        foo: "exports.bar = 42;" 
+      },
+      test: { 
+        map: "function(doc) { emit(doc._id, require('views/lib/foo').bar); }"
+      }
     }
    }
  }}}

Mime
View raw message