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/CALA2sAbZ3EynHE_rfP4AzeE%3DL1cdvabW%2BRi2kYrjD5ao6a6Ueg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
