Skip to content

Commit

Permalink
Resolves #4 and resolves #5
Browse files Browse the repository at this point in the history
  • Loading branch information
ClickerMonkey committed May 31, 2016
1 parent c952e91 commit 369e0a4
Show file tree
Hide file tree
Showing 10 changed files with 397 additions and 65 deletions.
20 changes: 20 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"bitwise": false,
"curly": true,
"eqeqeq": true,
"esversion": 5,
"freeze": true,
"funcscope": true,
"loopfunc": false,
"maxdepth": 5,
"noarg": true,
"nocomma": true,
"nonbsp": true,
"nonew": true,
"notypeof": true,
"predef": [ "MY_GLOBAL" ],
"shadow": true,
"singleGroups": false,
"undef": true,
"unused": false
}
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "4.0"
before_script:
- npm install -g gulp
18 changes: 17 additions & 1 deletion Gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ var sourcemaps = require('gulp-sourcemaps');
var plugins = require('gulp-load-plugins')();
var gutil = require('gulp-util');
var shell = require('gulp-shell');
var size = require('gulp-check-filesize');
var jshint = require('gulp-jshint');

var build = {
filename: 'rekord-pouchdb.js',
minified: 'rekord-pouchdb.min.js',
output: './build/',
include: [
'./src/rekord-pouchdb.js'
'./src/pouchdb.js'
]
};

Expand All @@ -24,6 +26,7 @@ var executeMinifiedBuild = function(props)
.pipe( plugins.concat( props.minified ) )
.pipe( plugins.uglify().on('error', gutil.log) )
.pipe( sourcemaps.write('.') )
.pipe( size({enableGzip: true}) )
.pipe( gulp.dest( props.output ) )
;
};
Expand All @@ -35,11 +38,24 @@ var executeBuild = function(props)
return gulp
.src( props.include )
.pipe( plugins.concat( props.filename ) )
.pipe( size({enableGzip: true}) )
.pipe( gulp.dest( props.output ) )
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
;
};
};

gulp.task('lint', function() {
return gulp
.src(build.output + build.filename)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
;
});

gulp.task( 'js:min', executeMinifiedBuild( build ) );
gulp.task( 'js', executeBuild( build ) );
gulp.task( 'default', ['js:min', 'js']);
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# <img src="https://raw.githubusercontent.com/Rekord/rekord/master/images/rekord-color.png" width="60"> rekord-pouchdb

[![Build Status](https://travis-ci.org/Rekord/rekord-pouchdb.svg?branch=master)](https://travis-ci.org/Rekord/rekord-pouchdb)
[![devDependency Status](https://david-dm.org/Rekord/rekord-pouchdb/dev-status.svg)](https://david-dm.org/Rekord/rekord-pouchdb#info=devDependencies)
[![Dependency Status](https://david-dm.org/Rekord/rekord-pouchdb.svg)](https://david-dm.org/Rekord/rekord-pouchdb)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Rekord/rekord/blob/master/LICENSE)
[![Alpha](https://img.shields.io/badge/State-Alpha-orange.svg)]()

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rekord-pouchdb",
"version": "1.0.0",
"version": "1.0.1",
"homepage": "https://github.com/Rekord/rekord-pouchdb",
"authors": [
"Philip Diffenderfer <pdiffenderfer@gmail.com>"
Expand Down
115 changes: 60 additions & 55 deletions src/neurosync-pouchdb.js → build/rekord-pouchdb.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
(function(PouchDB, Rekord, global, undefined)
(function(global, PouchDB, Rekord, undefined)
{

Rekord.Debugs.POUCH_INIT = 2000;
Rekord.Debugs.POUCH_ALL = 2001;
Rekord.Debugs.POUCH_ALL_ERROR = 2002;
Rekord.Debugs.POUCH_GET = 2003;
Rekord.Debugs.POUCH_GET_ERROR = 2004;
Rekord.Debugs.POUCH_CREATE = 2005;
Rekord.Debugs.POUCH_CREATE_ERROR = 2006;
Rekord.Debugs.POUCH_UPDATE = 2007;
Rekord.Debugs.POUCH_UPDATE_ERROR = 2008;
Rekord.Debugs.POUCH_REMOVE = 2009;
Rekord.Debugs.POUCH_REMOVE_ERROR = 2010;
Rekord.Debugs.POUCH_LIVE_REMOVE = 2011;
Rekord.Debugs.POUCH_LIVE_SAVE = 2012;
Rekord.Debugs.POUCH_LIVE_SAVE_IGNORE = 2013;

if ( Rekord.debugMap )
{
Rekord.debugMap[ Rekord.Debugs.POUCH_INIT ] = 'PouchDB Initialized';
Rekord.debugMap[ Rekord.Debugs.POUCH_ALL ] = 'PouchDB All';
Rekord.debugMap[ Rekord.Debugs.POUCH_ALL_ERROR ] = 'PouchDB All Error';
Rekord.debugMap[ Rekord.Debugs.POUCH_GET ] = 'PouchDB Get';
Rekord.debugMap[ Rekord.Debugs.POUCH_GET_ERROR ] = 'PouchDB Get Error';
Rekord.debugMap[ Rekord.Debugs.POUCH_CREATE ] = 'PouchDB Create';
Rekord.debugMap[ Rekord.Debugs.POUCH_CREATE_ERROR ] = 'PouchDB Create Error';
Rekord.debugMap[ Rekord.Debugs.POUCH_UPDATE ] = 'PouchDB Update';
Rekord.debugMap[ Rekord.Debugs.POUCH_UPDATE_ERROR ] = 'PouchDB Update Error';
Rekord.debugMap[ Rekord.Debugs.POUCH_REMOVE ] = 'PouchDB Remove';
Rekord.debugMap[ Rekord.Debugs.POUCH_REMOVE_ERROR ] = 'PouchDB Remove Error';
Rekord.debugMap[ Rekord.Debugs.POUCH_LIVE_REMOVE ] = 'PouchDB Live Remove';
Rekord.debugMap[ Rekord.Debugs.POUCH_LIVE_SAVE ] = 'PouchDB Live Save';
Rekord.debugMap[ Rekord.Debugs.POUCH_LIVE_SAVE_IGNORE ] = 'PouchDB Live Save Ignored';
}
var Debugs = Rekord.Debugs;

var cache = {};

var Rekord_live = Rekord.live;
var Rekord_rest = Rekord.rest;
var Rekord_store = Rekord.store;

Rekord.pouch = function(name, options)
Debugs.POUCH_INIT = 2000;
Debugs.POUCH_ALL = 2001;
Debugs.POUCH_ALL_ERROR = 2002;
Debugs.POUCH_GET = 2003;
Debugs.POUCH_GET_ERROR = 2004;
Debugs.POUCH_CREATE = 2005;
Debugs.POUCH_CREATE_ERROR = 2006;
Debugs.POUCH_UPDATE = 2007;
Debugs.POUCH_UPDATE_ERROR = 2008;
Debugs.POUCH_REMOVE = 2009;
Debugs.POUCH_REMOVE_ERROR = 2010;
Debugs.POUCH_LIVE_REMOVE = 2011;
Debugs.POUCH_LIVE_SAVE = 2012;
Debugs.POUCH_LIVE_SAVE_IGNORE = 2013;

if ( Rekord.debugMap )
{
Rekord.debugMap[ Debugs.POUCH_INIT ] = 'PouchDB Initialized';
Rekord.debugMap[ Debugs.POUCH_ALL ] = 'PouchDB All';
Rekord.debugMap[ Debugs.POUCH_ALL_ERROR ] = 'PouchDB All Error';
Rekord.debugMap[ Debugs.POUCH_GET ] = 'PouchDB Get';
Rekord.debugMap[ Debugs.POUCH_GET_ERROR ] = 'PouchDB Get Error';
Rekord.debugMap[ Debugs.POUCH_CREATE ] = 'PouchDB Create';
Rekord.debugMap[ Debugs.POUCH_CREATE_ERROR ] = 'PouchDB Create Error';
Rekord.debugMap[ Debugs.POUCH_UPDATE ] = 'PouchDB Update';
Rekord.debugMap[ Debugs.POUCH_UPDATE_ERROR ] = 'PouchDB Update Error';
Rekord.debugMap[ Debugs.POUCH_REMOVE ] = 'PouchDB Remove';
Rekord.debugMap[ Debugs.POUCH_REMOVE_ERROR ] = 'PouchDB Remove Error';
Rekord.debugMap[ Debugs.POUCH_LIVE_REMOVE ] = 'PouchDB Live Remove';
Rekord.debugMap[ Debugs.POUCH_LIVE_SAVE ] = 'PouchDB Live Save';
Rekord.debugMap[ Debugs.POUCH_LIVE_SAVE_IGNORE ] = 'PouchDB Live Save Ignored';
}

function pouch(name, options)
{
return name in cache ? cache[ name ] : cache[ name ] = new PouchDB( name, options );
};
}

Rekord.setRest(function(database)
function RestFactory(database)
{
if ( !database.api )
{
Expand All @@ -67,7 +69,7 @@
retry: true
});

Rekord.debug( Rekord.Debugs.POUCH_INIT, database, pouch );
Rekord.debug( Debugs.POUCH_INIT, database, pouch );

return {

Expand All @@ -77,7 +79,7 @@
{
function onAll(response)
{
Rekord.debug( Rekord.Debugs.POUCH_ALL, database, response );
Rekord.debug( Debugs.POUCH_ALL, database, response );

var values = [];
for (var i = 0; i < response.rows.length; i++)
Expand All @@ -90,7 +92,7 @@

function onAllError(err)
{
Rekord.debug( Rekord.Debugs.POUCH_ALL_ERROR, database, err );
Rekord.debug( Debugs.POUCH_ALL_ERROR, database, err );

failure( [], err.status );
}
Expand All @@ -104,15 +106,15 @@

function onGet(response)
{
Rekord.debug( Rekord.Debugs.POUCH_GET, database, model, key, response );
Rekord.debug( Debugs.POUCH_GET, database, model, key, response );

model._rev = response._rev;
success( response );
}

function onGetError(err)
{
Rekord.debug( Rekord.Debugs.POUCH_GET_ERROR, database, model, key, err );
Rekord.debug( Debugs.POUCH_GET_ERROR, database, model, key, err );

failure( null, err.status );
}
Expand All @@ -127,7 +129,7 @@

function onCreate(response)
{
Rekord.debug( Rekord.Debugs.POUCH_CREATE, database, model, encoded, response );
Rekord.debug( Debugs.POUCH_CREATE, database, model, encoded, response );

if ( response.ok )
{
Expand All @@ -143,7 +145,7 @@

function onCreateError(err)
{
Rekord.debug( Rekord.Debugs.POUCH_CREATE_ERROR, database, model, encoded, err );
Rekord.debug( Debugs.POUCH_CREATE_ERROR, database, model, encoded, err );

failure( null, err.status );
}
Expand All @@ -159,7 +161,7 @@

function onUpdate(response)
{
Rekord.debug( Rekord.Debugs.POUCH_UPDATE, database, model, encoded, response );
Rekord.debug( Debugs.POUCH_UPDATE, database, model, encoded, response );

if ( response.ok )
{
Expand All @@ -175,7 +177,7 @@

function onUpdateError(err)
{
Rekord.debug( Rekord.Debugs.POUCH_UPDATE_ERROR, database, model, encoded, err );
Rekord.debug( Debugs.POUCH_UPDATE_ERROR, database, model, encoded, err );

failure( null, err.status );
}
Expand All @@ -189,7 +191,7 @@

function onRemove(response)
{
Rekord.debug( Rekord.Debugs.POUCH_REMOVE, database, model, key, response );
Rekord.debug( Debugs.POUCH_REMOVE, database, model, key, response );

if ( response.ok )
{
Expand All @@ -203,7 +205,7 @@

function onRemoveError(err)
{
Rekord.debug( Rekord.Debugs.POUCH_REMOVE_ERROR, database, model, key, err );
Rekord.debug( Debugs.POUCH_REMOVE_ERROR, database, model, key, err );

failure( {}, err.status );
}
Expand All @@ -217,10 +219,9 @@
}

};
});

}

Rekord.setLive(function(database)
function LiveFactory(database)
{
if ( !database.api )
{
Expand All @@ -239,21 +240,21 @@
{
if ( change.deleted )
{
Rekord.debug( Rekord.Debugs.POUCH_LIVE_REMOVE, database, change );
Rekord.debug( Debugs.POUCH_LIVE_REMOVE, database, change );

database.liveRemove( change.id );
}
else
{
if ( change.doc.$origin !== database.origin )
{
Rekord.debug( Rekord.Debugs.POUCH_LIVE_SAVE, database, change );
Rekord.debug( Debugs.POUCH_LIVE_SAVE, database, change );

database.liveSave( change.id, change.doc );
}
else
{
Rekord.debug( Rekord.Debugs.POUCH_LIVE_SAVE_IGNORE, database, change );
Rekord.debug( Debugs.POUCH_LIVE_SAVE_IGNORE, database, change );
}
}
}
Expand All @@ -265,6 +266,10 @@
save: Rekord.noop,
remove: Rekord.noop
};
});
}

Rekord.pouch = pouch;
Rekord.setRest( RestFactory );
Rekord.setLive( LiveFactory );

})( PouchDB, Rekord, this );
})( this, this.PouchDB, this.Rekord );
2 changes: 2 additions & 0 deletions build/rekord-pouchdb.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 369e0a4

Please sign in to comment.