Skip to content

Instantly share code, notes, and snippets.

@radicaled
Last active August 29, 2015 14:07
Show Gist options
  • Save radicaled/a0bff41189de3e766e5a to your computer and use it in GitHub Desktop.
Save radicaled/a0bff41189de3e766e5a to your computer and use it in GitHub Desktop.
dart:js interop problems.
void map(doc, emit) {
emit(doc); // emit all documents
}
var db = new JsObject(context['PouchDB'], ['test_db']);
var jsPromise = db.callMethod('query', [map]);
// map ends up being wrapped like this:
// function () { return func(Array.prototype.slice.apply(arguments)); }
// PouchDB is expecting a function like this:
// function(doc, emit) { /* ... */ }
// but Dart is sending this:
// function () { return func(Array.prototype.slice.apply(arguments)); }
//
// Thus triggers the second branch.
if (typeof view.mapFun === "function" && view.mapFun.length === 2) {
var origMap = view.mapFun;
mapFun = function (doc) {
return origMap(doc, emit);
};
} else {
mapFun = evalFunc(view.mapFun.toString(), emit, sum, log, Array.isArray, JSON.parse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment