You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by Apache Wiki <wi...@apache.org> on 2010/12/01 18:46:37 UTC

[Couchdb Wiki] Update of "HTTP_view_API" by jpfiset

Dear Wiki user,

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

The "HTTP_view_API" page has been changed by jpfiset.
http://wiki.apache.org/couchdb/HTTP_view_API?action=diff&rev1=49&rev2=50

--------------------------------------------------

   * Keep in mind that the the Futon Web-Client silently adds ''group=true'' to your views.
  
  == Sharing Code Between Views ==
- There are no development plans to share code/functions between views.  Each view function is stored according to a hash of their byte representation, so it is important that a function does not load any additional code, changing its behavior without changing its byte-string.  Hence the use-case for [[http://github.com/couchapp/couchapp|CouchApp]].
+ There are no development plans to share code/functions between views.  Each view function is stored according to a hash of their byte representation, so it is important that a function does not load any additional code, changing its behavior without changing its byte-string.  Hence the use-case for [[http://github.com/couchapp/couchapp|CouchApp]]. In CouchApp, it is possible to include directives within any Javascript functions that directs CouchApp to modify the functions before they are uploaded to the CouchDb server.
+ 
+ An explanation of CouchApp directives is found in [[http://japhr.blogspot.com/2010/02/couchapp-templates-for-showing.html|Chris Strom's blog]]. Using CouchApp, one can insert Javascript code from a different file into a view map function using the "code" CouchApp directive. For example:
+ {{{#!highlight javascript
+ {
+   "map": "function(doc) { 
+     // Next line is CouchApp directive
+     // !code dir/file.js
+ 
+     // isADocOfInterest is defined in dir/file.js
+     if( isADocOfInterest(doc) ) {
+       emit(doc.key, doc);
+     }
+   }"
+ }
+ }}}
  
  Since CouchDB 0.11 it is possible to share code in {{{show}}}, {{{list}}}, {{{update}}}, and {{{validation}}} functions. See [[CommonJS_Modules]] for details.