J. Chris Anderson, can you help?

35 views
Skip to first unread message

Seung Chan Lim

unread,
Oct 2, 2014, 1:12:00 PM10/2/14
to mobile-c...@googlegroups.com
I think you're the only one who knows how to answer this. Would love your help.

(This is off of the other thread titled "J. Chris Anderson can you help? Re: filtering changes feed")

--------

Hi, I'm just getting around this. (went on a vacation)

So I see that now a dummy filter function that returns true works great. 

I'm still having trouble making my filter function work, and I'm guessing it has to do with the remark you made about decodeURIComponent and JSON.parse.

I tried throw JSON.stringify(req) as you suggested, but I'm not seeing it show up anywhere. Where does it show up? I have my safari developer console open which I use to debug my phonegap app.

Since I call it like this

http://lite.couchbase./status32/_changes?feed=continuous&include_docs=true&filter=utils/by_id&doc_ids=%4B%22id%22%5D

And my filter function looks like this

function(doc, req) { 
   if (req.query.doc_ids.indexOf(doc._id) != -1) { 

       return true;
   } else {
       return false;

   } 
       }

Are you saying I should:

var doc_ids = JSON.parse(decodeURIComponent(requ.query.doc_ids));
if (doc_ids.indexOf(doc._id) != -1)  {

return true;
}

Am I understanding you?

slim

J. Chris Anderson

unread,
Oct 7, 2014, 1:02:39 PM10/7/14
to mobile-c...@googlegroups.com


On Thursday, October 2, 2014 10:12:00 AM UTC-7, Seung Chan Lim wrote:
I think you're the only one who knows how to answer this. Would love your help.

(This is off of the other thread titled "J. Chris Anderson can you help? Re: filtering changes feed")

--------

Hi, I'm just getting around this. (went on a vacation)

So I see that now a dummy filter function that returns true works great. 

I'm still having trouble making my filter function work, and I'm guessing it has to do with the remark you made about decodeURIComponent and JSON.parse.

I tried throw JSON.stringify(req) as you suggested, but I'm not seeing it show up anywhere. Where does it show up? I have my safari developer console open which I use to debug my phonegap app.


Sorry about the delay. I just (duh) realized that the JS interpreter that runs the filters is not the WebView JS instance, so it won't have access to the console. Something might show up in the native log console...

Debugging from inside a sandbox is never fun. One approach to try to divine what's going on in there could be to test one piece of logic at a time. eg:

function(doc, req) {
 return !!req.query;
}

if all the docs come through you know "req" has a "query" property.

function(doc, req) {
  return !!req.query.doc_ids;
}

then you know it has a doc_ids property.

function(doc, req) {
  try {
JSON.parse(req.query.doc_ids)
return true
  } catch {
return false
  }
}

now you know if the decodeURIComponent is required or if the execution environment is handling it for you.

Etc.

Welcome to debugging a ship in a bottle. :)
Reply all
Reply to author
Forward
0 new messages