Created
March 27, 2013 05:26
-
-
Save crodjer/5251904 to your computer and use it in GitHub Desktop.
Promises in PouchDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// With the existing Pouch(dbname, callback) api | |
db = Pouch('adapter://identifier'); | |
data = { | |
dummy: true | |
}; | |
promise = db.post(data); // As soon as the db is available, post this data. | |
// For a callback, it can behave like promises | |
promise.then(function (response) { | |
// Do something with the object. | |
}, function (err, response){ | |
// Notify somebody that it failed. | |
}); | |
// All other methods which take callbacks follow the same pattern. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment