The easiest thing is to look at the first argument to the dbChanged function, which will be the document itself. From that you can see if the document would impact the user's current screen, and redraw conditionally.
As far as ignoring the first set of records, you can request the /mydatabase/ url to get the current local sequence number, if you pass that into the changes connection as a since parameter, it will start from there, skipping any older changes. The implementation of the since handling behavior is here: https://github.com/jchris/coax/blob/master/lib/coax.js#L74 It is also used so that subsequent changes requests start from the correct sequence. The continuous mode should only be used on server-side js due to XHR limitations, so I use longpoll by default in coax. As far as waiting until first sync is complete, you can parse the output of the _active_tasks API, like I do here: https://github.com/couchbaselabs/TodoLite-PhoneGap/blob/master/js/index.js#L797 Chris On Monday, April 14, 2014 11:04:02 AM UTC-7, Ami Kapadia wrote: > > Hi J.Chris Anderson, > Thanks for your response. > > Yes, I am using this API. I am doing synchronization at the time of > login. There can be thousands of records to be synced. > In that case, connectToChanges and window.dbChanged() will be called > thousand times. > > So, If I write logic of refreshing list in window.dbChanged(), it will > refresh list thousand times. > Can you tell me is there any flag which tells that synchronization is now > done. So, I can refresh list there. > > Also, How could I know which list is to update at which time. Suppose I am > having 5 views. So, every time after sync I have to update all 5 lists? > > Thanks! > Ami > > > On Mon, Apr 14, 2014 at 11:13 PM, J. Chris Anderson > <[email protected]>wrote: > >> The trick is to rerun your query whenever the database changes. To do >> this you can connect to the _changes API via the longpoll query: >> http://docs.couchbase.com/couchbase-lite/cbl-api/#get-db-changes >> >> Here is a place where I do it in code, by calling a changes API handler >> that I wrote. >> >> >> https://github.com/couchbaselabs/TodoLite-PhoneGap/blob/master/js/index.js#L59 >> >> Once I am listening to the feed, I use it to call a global function >> (window.onChange). My application swaps out that function depending on >> which view is active. >> >> If you want that module (coax) it is available on npm, or you can grab >> the modules.js file used by TodoLite-PhoneGap, and require it like this: >> https://github.com/couchbaselabs/TodoLite-PhoneGap/blob/master/js/index.js#L21 >> >> And instantiate it like this: >> https://github.com/couchbaselabs/TodoLite-PhoneGap/blob/master/js/index.js#L542 >> >> Here is the readme for coax: https://github.com/jchris/coax >> >> Hope that helps. >> >> >> On Monday, April 14, 2014 12:56:22 AM UTC-7, Ami Kapadia wrote: >>> >>> Hi! >>> >>> I am using CBL in my Phonegap application. I am creating native views >>> (Android and iOS). >>> *View v1 = db.getView(String.format("%s/%s",* >>> * strDbName,* >>> * "getrecords_typewise"));* >>> * v1.setMap(new Mapper() * >>> * {* >>> * @Override* >>> * public void map(Map<String, Object> document, Emitter emitter) * >>> * {* >>> * Object docType = document.get("type");* >>> * if (docType != null && * >>> * document.get("is_active") != null * >>> * && document.get("is_active").equals(true))* >>> * {* >>> * emitter.emit(docType.toString(), document);* >>> * }* >>> * }* >>> * }, strVersion);* >>> * db.registerView(v1);* >>> >>> Then I am querying views from JavaScript like this : >>> *config.views(["getrecords_typewise", {* >>> >>> * startkey : "contact",* >>> >>> * endkey : "contact",* >>> >>> * descending : true* >>> >>> * }], function(err, view)* >>> * {* >>> * var len = view['rows'].length;* >>> >>> *});* >>> >>> >>> I want to use live queries and on dbChange, I will update my associated >>> UI list. How can I do this? >>> >> -- >> You received this message because you are subscribed to the Google Groups >> "Couchbase Mobile" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/mobile-couchbase/e8a3bf27-c58c-4f56-b777-d138f5f44faf%40googlegroups.com<https://groups.google.com/d/msgid/mobile-couchbase/e8a3bf27-c58c-4f56-b777-d138f5f44faf%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/719a6607-1686-43cd-9387-abb99659966e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
