Using Knockout.js with CouchDB - Update on Change

It’s just interesting to know how best to subscribe to my CouchDB datastore in order to update the document on the couch, the KO view will also be updated (automatically). Is it possible, what is possible?

The following is what I have so far that just get the username from the user_info document.

$.getJSON('http://localhost/couchdb/user_info', function(data) { var viewModel = ko.mapping.fromJS(data); ko.applyBindings(viewModel); }); 

Any help would be greatly appreciated!

+6
source share
2 answers

CouchDB supports notifications when documents change: changes the feed .

You can poll the change channel with parameter ?since=X to get only updates from X.

You can also "long poll" the feed by adding &feed=longpoll . If there are no changes yet, CouchDB will receive your request, but will not respond until, finally, the change occurs.

Or you can have a full COMET style stream by adding &feed=continuous . This is similar to longpoll, however CouchDB never closes the connection. Each time a change occurs, it sends you JSON and then continues to wait.

Finally, you can receive notifications of any changes in the database or point to the Javascript filter to run on the server ( &filter=designdoc/filtername ). You will only receive notifications if the filter approves.

+5
source

You looked at http://hood.ie/ , that's good. I also run hoodie as a os_daemons service from inside my couchdb.

It's nice.

+1
source

Source: https://habr.com/ru/post/894610/


All Articles