Skip to content
This repository has been archived by the owner on Jun 17, 2022. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tlvince committed Jul 24, 2014
0 parents commit f031001
Show file tree
Hide file tree
Showing 13 changed files with 407 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# editorconfig.org

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bower_components
node_modules
24 changes: 24 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"node": true,
"browser": true,
"esnext": true,
"bitwise": true,
"camelcase": true,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
"latedef": true,
"newcap": true,
"noarg": true,
"quotmark": "single",
"regexp": true,
"undef": true,
"unused": true,
"strict": true,
"trailing": true,
"smarttabs": true,
"globals": {
"angular": false
}
}
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- '0.10'
before_script:
- npm install --global bower
- bower install
22 changes: 22 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License

© 2013-2014 Wilfred Springer <http://nxt.flotsam.nl>
© 2014 Tom Vincent <http://tlvince.com/contact>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# angular-pouchdb

[![Build Status][travis-image]][travis-url]

> AngularJS wrapper for PouchDB
A lightweight AngularJS service for PouchDB that;

* Wraps Pouch's methods with `$q`
* Makes Angular aware of asynchronous updates (via `$rootScope.$apply`)

[travis-image]: https://travis-ci.org/angular-pouchdb/angular-pouchdb.svg
[travis-url]: https://travis-ci.org/angular-pouchdb/angular-pouchdb

## Usage

1. Install `angular-pouchdb` via Bower:

```bash
bower install --save angular-pouchdb/angular-pouchdb
```

2. Add `pouchdb` as a module dependency:

```js
angular.module('app', ['pouchdb']);
```

3. Inject the `pouchdb` service in your app:

```js
angular.service('service', function(pouchdb) {});
```

## Authors

* © 2013-2014 Wilfred Springer <http://nxt.flotsam.nl>
* © 2014 Tom Vincent <http://tlvince.com/contact>

## License

Released under the MIT License.
71 changes: 71 additions & 0 deletions angular-pouchdb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict';

angular.module('pouchdb', [])
.factory('PouchDB', function($q, $rootScope, $window) {
function qify(fn) {
return function() {
var deferred = $q.defer();
function callback(err, res) {
return $rootScope.$apply(function() {
if (err) {
return deferred.reject(err);
} else {
return deferred.resolve(res);
}
});
}
var args = [];
if (arguments !== null) {
args = Array.prototype.slice.call(arguments);
}
args.push(callback);
fn.apply(this, args);
return deferred.promise;
};
}

var methods = [
'destroy',
'put',
'post',
'get',
'remove',
'bulkDocs',
'allDocs',
'sync',
'putAttachment',
'getAttachment',
'removeAttachment',
'query',
'viewCleanup',
'info',
'compact',
'revsDiff'
];

return function PouchDB(name, options) {
var db = new $window.PouchDB(name, options);

var api = {};
methods.forEach(function(method) {
api[method] = qify(db[method].bind(db));
});

api.changes = function(options) {
var clone = angular.copy(options);
clone.onChange = function(change) {
return $rootScope.$apply(function() {
return options.onChange(change);
});
};
return db.changes(clone);
};

api.replicate = {
to: db.replicate.to.bind(db),
from: db.replicate.from.bind(db),
};

return api;
};
});
38 changes: 38 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "angular-pouchdb",
"version": "1.0.0",
"authors": [
"Wilfred Springer <wilfredspringer@gmail.com>",
"Tom Vincent <http://tlvince.com/contact>"
],
"description": "AngularJS wrapper for PouchDB",
"main": "angular-pouchdb.js",
"keywords": [
"angularjs",
"pouchdb"
],
"license": "MIT",
"homepage": "https://github.com/angular-pouchdb/angular-pouchdb",
"ignore": [
"**/.*",
"karma.conf.js",
"node_modules",
"bower_components",
"test",
"package.json"
],
"dependencies": {
"angular": "~1.2.20",
"pouchdb": "~2.2.3"
},
"devDependencies": {
"angular-mocks": "~1.2.20",
"es5-shim": "~4.0.1",
"jasmine-as-promised": "~0.0.8"
},
"overrides": {
"jasmine-as-promised": {
"dependencies": {}
}
}
}
56 changes: 56 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'use strict';

var bowerJS = require('wiredep')({
devDependencies: true
}).js;

module.exports = function(config) {
config.set({

// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',

// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['jasmine'],

// list of files / patterns to load in the browser
files: bowerJS.concat([
'angular-pouchdb.js',
'test/*.js'
]),

// list of files to exclude
exclude: [],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {},

// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['progress'],

// web server port
port: 9876,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['PhantomJS'],

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true
});
};
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "angular-pouchdb",
"version": "1.0.0",
"description": "AngularJS wrapper for PouchDB",
"main": "angular-pouchdb.js",
"scripts": {
"test": "./node_modules/karma/bin/karma start",
"watch": "./node_modules/karma/bin/karma start --autoWatch true --singleRun false"
},
"repository": {
"type": "git",
"url": "https://github.com/angular-pouchdb/angular-pouchdb.git"
},
"keywords": [
"angular",
"pouchdb"
],
"author": "Tom Vincent <npm@tlvince.com> (http://tlvince.com/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/angular-pouchdb/angular-pouchdb/issues"
},
"homepage": "https://github.com/angular-pouchdb/angular-pouchdb",
"devDependencies": {
"karma": "^0.12.17",
"karma-jasmine": "^0.1.5",
"karma-phantomjs-launcher": "^0.1.4",
"wiredep": "^1.8.2"
}
}
23 changes: 23 additions & 0 deletions test/.jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "../.jshintrc",
"globals": {
"after": false,
"afterEach": false,
"angular": false,
"before": false,
"beforeEach": false,
"browser": false,
"describe": false,
"ddescribe": false,
"xdescribe": false,
"expect": false,
"inject": false,
"it": false,
"iit": false,
"xit": false,
"jasmine": false,
"spyOn": false,
"runs": false,
"waitsFor": false
}
}
Loading

0 comments on commit f031001

Please sign in to comment.