문제

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