Skip to content

Instantly share code, notes, and snippets.

@trisapeace
Created September 26, 2012 01:08
Show Gist options
  • Select an option

  • Save trisapeace/3785402 to your computer and use it in GitHub Desktop.

Select an option

Save trisapeace/3785402 to your computer and use it in GitHub Desktop.
eval() problem workaround
// An object of couch view functions that we use
// Note that spacing is very important.
// Do not reformat these values
var validCouchViews = {
getAllIdsByDate : function(doc) {if (doc.dateModified) {emit(doc.dateModified, doc);}},
searchByQueryString : function(doc) {if ((doc.datumFields) && (doc.session)) {var obj = {};for (i = 0; i < doc.datumFields.length; i++) {if (doc.datumFields[i].mask) {obj[doc.datumFields[i].label] = doc.datumFields[i].mask;}}if (doc.session.sessionFields) {for (j = 0; j < doc.session.sessionFields.length; j++) {if (doc.session.sessionFields[j].mask) {obj[doc.session.sessionFields[j].label] = doc.session.sessionFields[j].mask;}}}emit(obj, doc._id);}}
};
for (var view in validCouchViews) {
if (fun.map.toString() == validCouchViews[view].toString()) {
fun.map = validCouchViews[view];
break;
}
}
var viewQuery = function(fun, idb, options) {
...
var emit = function(key, val) { ... };
...
// fun.map is a function that calls emit(k, v)
eval('fun.map = ' + fun.map.toString() + ';');
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment