Skip to content

Commit

Permalink
sync bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-johnson committed Jan 12, 2015
1 parent bc3b2ab commit 3731f14
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ When `.connect()` is called, the database will listen to the database changes fe

## Documentation

For quick documentation, please see the inline comments in the source code. These comments are written in markdown, so you can also build them for a prettier experience.
For quick documentation on each function, please see the inline comments in the source code. These comments are in [Doxxo](https://github.com/BeneathTheInk/doxxo) format, so you can also build them for a prettier experience.

```bash
npm run build-docs
Expand Down
8 changes: 4 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function Lazybones(name, opts) {
// create PouchDB instance from options
this.pouch = opts.pouch instanceof PouchDB ? opts.pouch : new PouchDB(name, opts.pouch);

// set the database on the object for easy access
// set the database name on the object for easy access
Object.defineProperty(this, "name", {
value: name,
writeable: false,
Expand Down Expand Up @@ -132,7 +132,7 @@ _.extend(Lazybones.prototype, {
conflicts: true,
returnDocs: false,
live: true
}, _.pick(options, utils.pouchOptionKeys.changes), {
}, options, {
include_docs: true
}))

Expand Down Expand Up @@ -313,7 +313,7 @@ _.extend(Lazybones.prototype, {
// return result async
.map(function(result, index) {
// resolve or reject depending on result
docs[index][result.ok ? "resolve" : "reject"](result);
docs[index][result.error ? "reject" : "resolve"](result);

// remove from the queue if resolution was successful
delete queue[ids[index]];
Expand All @@ -323,7 +323,7 @@ _.extend(Lazybones.prototype, {
}, { concurrency: 20 })

// after a successful write, invalidate the queue again
.then(this._invalidateWrites)
.then(this._invalidateWrites);
})

// always, always reset state
Expand Down
6 changes: 3 additions & 3 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ module.exports = function sync(method, model, options) {
case "read":
// fetch single if document
if (isdoc) {
pouch_opts = _.defaults(_.pick(options, utils.pouchOptionKeys.get), {
pouch_opts = _.extend({
conflicts: true,
attachments: false
});
}, options);

return Promise.cast(db.pouch.get(id, pouch_opts)).tap(options.success);
}
Expand All @@ -71,7 +71,7 @@ module.exports = function sync(method, model, options) {
pouch_opts = _.extend({
conflicts: true,
attachments: false
}, _.pick(options, utils.pouchOptionKeys.allDocs), {
}, options, {
include_docs: true // always must include the full document
});

Expand Down
14 changes: 2 additions & 12 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,6 @@ exports.uuid = PouchDB.utils.uuid;
*/
exports.Promise = Promise;

/**
* ### pouchOptionKeys
*
* Lists of option keys by method names that can be used in PouchDB requests. This allows option objects to be sanitized before being passed to PouchDB.
*/
exports.pouchOptionKeys = {
get: [ "rev", "revs", "revs_info", "open_revs", "conflicts", "attachments", "local_seq", "ajax" ],
allDocs: [ "include_docs", "conflicts", "attachments", "startkey", "endkey", "inclusive_end", "limit", "skip", "descending", "key", "keys" ],
changes: [ "include_docs", "conflicts", "attachments", "filter", "doc_ids", "since", "live", "limit", "style", "view", "returnDocs", "batch_size" ]
};

/**
* ### parse()
*
Expand Down Expand Up @@ -155,7 +144,8 @@ LazyError.errors = {
*/
exports.transformPouchError = function(e) {
// make sure this is a real pouch error
if (!(e || e.error)) throw e;
if (!e) throw new LazyError;
if (!e.error || e instanceof LazyError) throw e;

var nerr = new LazyError("POUCH_ERROR", e.message);
nerr.error = true; // keep it consistent
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ describe("Live Sync", function() {

describe("Conflicts", function() {

});
});

0 comments on commit 3731f14

Please sign in to comment.