Skip to content

Commit

Permalink
(#1387) - prototype based plugins api
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinmetcalf committed Feb 27, 2014
1 parent d82e745 commit 904838d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 28 deletions.
17 changes: 0 additions & 17 deletions lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,6 @@ function PouchDB(name, opts, callback) {
callback(null, self);

});
for (var plugin in PouchDB.plugins) {
if (PouchDB.plugins.hasOwnProperty(plugin)) {

// In future these will likely need to be async to allow the plugin
// to initialise
var pluginObj = PouchDB.plugins[plugin](self);
for (var api in pluginObj) {
if (pluginObj.hasOwnProperty(api)) {
// We let things like the http adapter use its own implementation
// as it shares a lot of code
if (!(api in self)) {
self[api] = pluginObj[api];
}
}
}
}
}
if (opts.skipSetup) {
self.taskqueue.ready(self);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ PouchDB.adapter('https', httpAdapter);

PouchDB.adapter('idb', require('./adapters/idb'));
PouchDB.adapter('websql', require('./adapters/websql'));
PouchDB.plugin('mapreduce', require('pouchdb-mapreduce'));
PouchDB.plugin(require('pouchdb-mapreduce'));

if (!process.browser) {
var ldbAdapter = require('./adapters/leveldb');
Expand Down
12 changes: 4 additions & 8 deletions lib/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@ PouchDB.destroy = utils.toPromise(function (name, opts, callback) {
var backend = PouchDB.parseAdapter(opts.name || name);
var dbName = backend.name;

for (var plugin in PouchDB.plugins) {
if (PouchDB.plugins.hasOwnProperty(plugin)) {
PouchDB.plugins[plugin]._delete(dbName);
}
}

// call destroy method of the particular adaptor
PouchDB.adapters[backend.adapter].destroy(dbName, opts, callback);
});
Expand All @@ -70,8 +64,10 @@ PouchDB.adapter = function (id, obj) {
}
};

PouchDB.plugin = function (id, obj) {
PouchDB.plugins[id] = obj;
PouchDB.plugin = function (obj) {
Object.keys(obj).forEach(function (id) {
PouchDB.prototype[id] = utils.toPromise(obj[id]);
});
};

module.exports = PouchDB;
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pouchdb",
"version": "1.2.0-alpha",
"version": "2.0.0-alpha",
"description": "PouchDB is a pocket-sized database.",
"release": "nightly",
"main": "./lib/index.js",
Expand All @@ -18,7 +18,7 @@
],
"dependencies": {
"request": "~2.28.0",
"pouchdb-mapreduce": "0.6.2",
"pouchdb-mapreduce": "git:https://github.com/pouchdb/mapreduce.git#prototype",
"bluebird": "~1.0.0",
"level-sublevel": "~5.2.0",
"levelup": "~0.18.2",
Expand Down

0 comments on commit 904838d

Please sign in to comment.