pouchdb: 'emit' function not defined
hello.
I am creating secondary index like this
var assetSearchIndex = {
_id: '_design/assetSearchIndex',
views: {
byAssetNum: {
map: function(asset, emit) {
emit(asset.ASSETNUM);
}.toString()
}
}
};
However when index is being built, I receive multiple errors
TypeError: emit is not a function
After some debugging I found out that I should not receive emit as param, because it exists in upper scope, when map function is eval-ed.
I think this is not correct, because:
- it is inconsistent with temp index syntax
- map is using ‘emit’ which is not passed nor defined (this also causes eslint validator errors)
Thanks, Vlad
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 18 (2 by maintainers)
obtive o mesmo problema utilizando typescript e pouchdb , couchdb ao criar Persistent queries. como solução e levando em conta que não será o type script que executara a function e sim o couchdb
I also am using that workaround, but the problem is that I don`t like hacks.
global variables with such common name should not exist.
sorry guys, but if it is possible to not use global variable, then one shouldn`t. this is one of the basic rules. it is also bad idea to make “JSON object, toJSON, isArray, sum, etc” declared as global without any namespace, because those names are quite common and it will lead to conflicts with either other libraries or new browser API in future.
“Optional keyword-only arguments may help here, but I’m not sure if JS supports this feature or will in the nearest future.” this feature is not supported, but from my experience 2-3 arguments are not too much. In this case only 2 is enough.
@fiatjaf - if you read my text above more attentively, you will see that I am aware that emit is defined on the run time (taken from upper scope).
@VladyslavGoloshchapov for what it’s worth, I stumbled upon this same issue using Pouch with Ionic 2 and was able to work around it by trusting @nolanlawson that emit is in the global scope and cheating the ts compiler with
declare function emit (val: any);
.I have not tested extensively just yet but seems to be ok, I’ve also not tested AoT compilation with this either.