Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Created July 19, 2014 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nolanlawson/118ce6bd7be863c9a8a0 to your computer and use it in GitHub Desktop.
Save nolanlawson/118ce6bd7be863c9a8a0 to your computer and use it in GitHub Desktop.
PouchDB issue 2493
<html>
<body>
<script src="//cdnjs.cloudflare.com/ajax/libs/pouchdb/2.2.3/pouchdb.min.js"></script>
<script src="index.js"></script>
<button onclick="edit()">Edit</button>
</body>
</html>
var todo = null;
var db = new PouchDB('todos');
var remoteCouch = 'http://user:password@127.0.0.1:5984/todos';
db.info(function(err, info) {
db.changes({
since: info.update_seq,
live: true
});
});
db.allDocs({include_docs: true, descending: true}, function(err, doc) {
if (doc.rows.length == 0) {
db.post({title: 'clean dishes'});
} else {
todo = doc.rows[0].doc;
}
});
var opts = {live: true};
db.replicate.to(remoteCouch, opts);
db.replicate.from(remoteCouch, opts);
function edit() {
todo.title = 'take out trash at ' + (new Date()).toUTCString();
console.log(todo);
db.put(todo);
// This doesn't solve the problem either
// db.put(todo).then(function(response) {
// todo._rev = response.rev;
// });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment