سؤال

According to the PouchDB replicate() documentation it's possible to add a continuous option to Pouch.replicate():

If true starts subscribing to changes in the first database and replicating them to the second.

I understand what this means, but how does it work? I've looked at the code, but it's hard to understand how 'subscribing' is accomplished.

هل كانت مفيدة؟

المحلول

It depends on what the first database is.

If it is a remote CouchDB, pouch makes an xhr request to the db/_changes resource for that couchdb (http://wiki.apache.org/couchdb/HTTP_database_API#Changes). It does indeed set feed=longpoll, as Kim mentioned. The longpoll option makes couch wait until there is a change before it sends anything- this way you don't poll over an over only to find there were no changes.

If the first database is a local PouchDB, it listens for "change" events, which are triggered whenever a change is made in the database.

Either way, when the replicator sees a change come in, it replicates it to the second database.

نصائح أخرى

I haven't read the PouchDB code, but the only way to do that is to listen to the _changes feed, probably with feed set to long-polling or continuous.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top