Skip to content

Instantly share code, notes, and snippets.

@nolanlawson
Last active August 29, 2015 14:07
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/7c32861af5d31a8fac4a to your computer and use it in GitHub Desktop.
Save nolanlawson/7c32861af5d31a8fac4a to your computer and use it in GitHub Desktop.
The changes feed
<html>
<body>
<pre id="display"></pre>
<script src="//cdn.jsdelivr.net/pouchdb/latest/pouchdb.min.js"></script>
<script src="index.js"></script>
</body>
</html>
// Destroy the database before doing anything, because I want
// you to see the same thing if you reload.
// Ignore the man behind the curtain!
new PouchDB('sample').destroy().then(function () {
return new PouchDB('sample');
}).then(function (db) {
function log(str) {
var display = document.getElementById('display');
display.innerHTML = display.innerHTML || '';
display.innerHTML += '\n' + str;
}
//
// IMPORTANT CODE STARTS HERE
//
db.put({_id: 'firstDoc', version: 1}).then(function () {
return db.put({_id: 'secondDoc', version: 1});
}).then(function () {
return db.get('secondDoc');
}).then(function (doc) {
doc.version = 2;
return db.put(doc);
}).then(function () {
return db.put({_id: 'thirdDoc', version: 1});
}).then(function () {
return db.changes({
since: 0,
include_docs: true
});
}).then(function (changes) {
log('Found the following changes:');
changes.results.forEach(function (change) {
log(JSON.stringify(change));
});
}).catch(function (err) {
// handle errors
})
//
// IMPORTANT CODE ENDS HERE
//
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment