Skip to content

Commit

Permalink
added load() method
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-johnson committed Jan 12, 2015
1 parent 3731f14 commit a9aa2ea
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ module.exports = function(grunt) {
clean: [ "dist/*.js" ],
browserify: {
dist: {
src: "lib/index.js",
src: "lib/lazybones.js",
dest: "dist/lazybones.js",
options: {
browserifyOptions: { standalone: "Lazybones" }
}
},
dev: {
src: "lib/index.js",
src: "lib/lazybones.js",
dest: "dist/lazybones.dev.js",
options: {
browserifyOptions: { debug: true, standalone: "Lazybones" }
Expand Down
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 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.
We have [pretty HTML docs](http://beneaththeink.github.io/lazybones/lazybones.html) with inline source code hosted on Github Pages. This documentation is generated from block-level comments in the code using [Doxxo](https://github.com/BeneathTheInk/doxxo), so you can also build them locally.

```bash
npm run build-docs
Expand Down
26 changes: 24 additions & 2 deletions lib/index.js → lib/lazybones.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ _.extend(Lazybones.prototype, {
/**
* ### connect()
*
* Listens to the PouchDB changes feed and replicates any changes to the in-memory documents. By default, the changes are "live" meaning that future changes will listened for. Use the `.disconnect()` to stop a live connection.
* Listens to the PouchDB changes feed and replicates any changes to the in-memory documents. By default, the changes are "live" meaning that future changes will listened for. Use `db.disconnect()` to stop a live connection.
*
* `this` is returned for method chaining.
*
Expand Down Expand Up @@ -127,7 +127,7 @@ _.extend(Lazybones.prototype, {

// the listener
var listener =
this._pouchChange = this.pouch.changes(_.extends({
this._pouchChange = this.pouch.changes(_.extend({
attachments: false,
conflicts: true,
returnDocs: false,
Expand Down Expand Up @@ -185,6 +185,28 @@ _.extend(Lazybones.prototype, {
return this;
},

/**
* ### load()
*
* A combination of `db.fetch()` and `db.connect()`. This will fetch from the database so all the current documents are in-memory, then it begins a live connection that starts from the current update sequence. In this way the database can catch up very quickly, but also respond to future database changes.
*
* This method returns a promise that is resolved when the database has been fetched and the live replication has started.
*/
load: function(options) {
options = options || {};

// get the database info to get the last sequence number
return Promise.cast(this.pouch.info()).bind(this)

// fetch the database for a super-fast catch up
.tap(function() { return this.fetch(options); })

// connect, starting at the last sequence
.then(function(info) {
return this.connect(_.extend({}, options, { since: info.update_seq }));
});
},

/**
* ### destroy()
*
Expand Down
2 changes: 1 addition & 1 deletion lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var _ = require("underscore"),
debug = require("debug")("lazybones:sync"),
utils = require("./utils"),
Document = require("./document"),
Database = require("./"),
Database = require("./lazybones"),
Promise = require("bluebird");

function noop(){}
Expand Down
18 changes: 9 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "lazybones",
"description": "An object-oriented abstraction of PouchDB using Backbone models and collections.",
"version": "0.1.5",
"version": "0.1.6",
"author": "Beneath the Ink <[email protected]>",
"contributors": [
{
Expand All @@ -20,27 +20,27 @@
"scripts": {
"dev": "node test/browser",
"test": "grunt build-test && ./node_modules/.bin/mocha test",
"build-docs": "./node_modules/.bin/doxxo -l bti ./lib/*.js"
"build-docs": "./node_modules/.bin/doxxo -i README.md -l bti lib/*.js README.md"
},
"main": "lib/index.js",
"main": "lib/lazybones.js",
"dependencies": {
"backbone": "~1.1.2",
"bluebird": "~2.3.11",
"debug": "~2.1.0",
"pouchdb": "~3.2.0",
"bluebird": "~2.6.4",
"debug": "~2.1.1",
"pouchdb": "~3.2.1",
"underscore": "~1.7.0"
},
"devDependencies": {
"chai": "~1.10.0",
"grunt": "~0.4.5",
"grunt-browserify": "~3.2.1",
"grunt-contrib-clean": "~0.6.0",
"grunt-contrib-uglify": "~0.6.0",
"grunt-contrib-uglify": "~0.7.0",
"grunt-contrib-watch": "~0.6.1",
"grunt-wrap2000": "~0.1.0",
"minimist": "~1.1.0",
"mocha": "~2.0.1",
"doxxo": "~0.1.4"
"mocha": "~2.1.0",
"doxxo": "~0.1.5"
},
"license": "MIT",
"keywords": [
Expand Down

0 comments on commit a9aa2ea

Please sign in to comment.