Skip to content

Commit

Permalink
(#1264 pouchdb/mapreduce#37) - document eval avoidance
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Jan 30, 2014
1 parent c723ba9 commit bc50047
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions docs/api.md
Expand Up @@ -541,6 +541,36 @@ db.query({map: map}, {reduce: false}, function(err, response) { });
}
{% endhighlight %}

if you pass a function to db.query and give it 'emit' as the second argument, then you can use a closure, (otherwise we have to use eval to bind emit)
{% highlight js %}
//BAD! will throw error
(function (id) {
db.query(function(doc) {
if(doc._id === id) {
emit(doc);
}
}).then(dance);
}(something));

//will be fine
(function (id) {
db.query(function(doc, emit) {
if(doc._id === id) {
emit(doc);
}
}).then(dance);
}(something));
{% endhighlight %}
You don't actuallly have to call them by those names though
{% highlight js %}
(function (id) {
db.query(function(thisIs, awesome) {
if(thisIs._id === id) {
awesome(thisIs);
}
}).then(dance);
}(something));
{% endhighlight %}
**Notes:**

1. Local databases do not currently support view caching; everything is a live view.
Expand Down

0 comments on commit bc50047

Please sign in to comment.