-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't pass a closure to db.query #1264
Comments
yes this is a known error, there is no way to get emit to be in scope without destroying the closure, though that gives me an idea |
FWIW this works: new Function('doc',
'if (doc.type === ' + JSON.stringify(what) + ')' +
'emit(doc._id, doc);'
); But it makes me cry a little bit |
Does emit really need to be in scope? I'd prefer taking the emitter as an argument to the function .. or if that's too verbose, even using |
I'm literally working on a pull to map reduce that takes emit as the second On Wed, Jan 29, 2014 at 2:15 PM, Eric Springer notifications@github.comwrote:
-Calvin W. Metcalf |
Only problem with that is it breaks compatibility with couchdb, so you can't use the same map function as you do in couch (e.g. in a design doc) because |
@chesles this only applies to the temp views, not the design doc views, as they are stringified anyway so they have to be evaled |
Ah, nice. That's awesome. +1 :) |
fyi I do have a pull for couchdb to get this syntax in apache/couchdb#127 |
The new feature is merged in pouchdb/mapreduce. If you can't wait for the next release and want to try the bleeding edge, I've built it here: pouchdb-nightly.js and pouchdb-nightly.min.js. var pouch = new PouchDB('mydb');
pouch.post({foo:'bar'})
.then(function(){
var myFoo = 'bar';
return pouch.query(function(doc, emit){
if (doc.foo === myFoo){
emit('it works!');
}
});
})
.then(function(result){
console.log(result.rows[0].key); // 'it works!'
}); Oh yeah, did I mention the next version of Pouch will have promises?! @calvinmetcalf has been tearing it up recently. |
Documentation here btw. |
Awesome. By the way, my angular-pouchdb wrapper uses Angular's $q promise, if anyone is interested. |
(#1264 pouchdb/mapreduce#37) - document eval avoidance
(#1264 pouchdb/mapreduce#37) - document eval avoidance
Example:
Gives:
Uncaught ReferenceError: what is not defined
The text was updated successfully, but these errors were encountered: