backbone-pouch-collection
Advanced tools
Comparing version 0.2.0 to 0.3.0
16
index.js
@@ -17,6 +17,11 @@ 'use strict'; | ||
if (method === 'read') { | ||
var opts = typeof this.opts == 'function' ? this.opts() : this.opts | ||
_.defaults(options.couch || (options.couch = {}), opts.params) | ||
var opts = this.opts || {} | ||
opts = typeof opts == 'function' ? opts() : opts | ||
_.defaults(options.couch || (options.couch = {}), opts.params, { | ||
include_docs: true | ||
}) | ||
if (opts.view === '_all_docs') { | ||
// default to '_all_docs' if view isn't specified | ||
if (opts.view === '_all_docs' || !opts.view) { | ||
promise = this.db.allDocs(options.couch, cb) | ||
@@ -39,7 +44,8 @@ } else { | ||
if (options.couch && options.couch.include_docs) | ||
if (options.couch && options.couch.include_docs) { | ||
return res.rows.map(function (row) { return row.doc }) | ||
else | ||
} else { | ||
return res | ||
} | ||
} | ||
}) |
{ | ||
"name": "backbone-pouch-collection", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Backbone Collections with PouchDB as the data source", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -18,2 +18,6 @@ backbone-pouch-collection | ||
`opts.view` can also be `_all_docs` to query...well... `_all_docs`. | ||
The defaults are `_all_docs` and `include_docs: true`. | ||
```javascript | ||
@@ -35,4 +39,2 @@ var PouchBase = require('backbone-pouch-collection') | ||
`opts.view` can also be `_all_docs` to query...well... `_all_docs`. | ||
You can also pass options to `collection.fetch()` to override the | ||
@@ -39,0 +41,0 @@ default. |
@@ -186,3 +186,47 @@ var assert = require('assert') | ||
}) | ||
it('should have defaults', function (done) { | ||
var child = new PouchBase() | ||
child.db = this.db | ||
var promise = child.fetch({ | ||
success: function (collection, res, opts) { | ||
assert(opts) | ||
assert(opts.couch, 'should have couch options') | ||
assert.equal(collection.length, 5) | ||
assert.equal(res.rows.length, 5) | ||
assert(opts.couch.include_docs, 'include_docs should be default') | ||
done() | ||
}, | ||
error: function (err) { done(err) } | ||
}) | ||
assert(promise) | ||
}) | ||
it('include_docs', function (done) { | ||
var child = new PouchBase() | ||
child.db = this.db | ||
child.opts = { | ||
params: { | ||
startkey: '_design/', | ||
endkey: '_design/\ufff0' | ||
} | ||
} | ||
var promise = child.fetch({ | ||
success: function (collection, res, opts) { | ||
assert(opts) | ||
assert(opts.couch, 'should have couch options') | ||
assert.equal(collection.length, 1) | ||
assert.equal(res.rows.length, 1) | ||
assert(opts.couch.include_docs, 'include_docs should be default') | ||
done() | ||
}, | ||
error: function (err) { done(err) } | ||
}) | ||
assert(promise) | ||
}) | ||
}) | ||
}) |
9490
235
63
1