Skip to content

Commit

Permalink
(#3839) - Use lie as promise polyfill everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
daleharvey committed Jun 21, 2015
1 parent 1d98f4b commit 72f1f0d
Show file tree
Hide file tree
Showing 13 changed files with 21 additions and 36 deletions.
18 changes: 8 additions & 10 deletions bin/build-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
'use strict';

var http_server = require('http-server');
var bluebird = require('bluebird');
var fs = bluebird.promisifyAll(require('fs'));
var Promise = require('lie');
var fs = require('fs');
var watchGlob = require('watch-glob');
var replace = require('replace');
var exec = require('child-process-promise').exec;
var mkdirp = bluebird.promisify(require('mkdirp'));
var mkdirp = require('mkdirp');

var POUCHDB_CSS = __dirname + '/../docs/static/css/pouchdb.css';
var POUCHDB_LESS = __dirname + '/../docs/static/less/pouchdb/pouchdb.less';
Expand All @@ -24,12 +24,10 @@ function checkJekyll() {
}

function buildCSS() {
return mkdirp(__dirname + '/../docs/static/css').then(function () {
var cmd = __dirname + '/../node_modules/less/bin/lessc ' + POUCHDB_LESS;
return exec(cmd);
}).then(function (child) {
return fs.writeFileAsync(POUCHDB_CSS, child.stdout);
}).then(function () {
mkdirp.sync(__dirname + '/../docs/static/css');
var cmd = __dirname + '/../node_modules/less/bin/lessc ' + POUCHDB_LESS;
return exec(cmd).then(function (child) {
fs.writeFileSync(POUCHDB_CSS, child.stdout);
console.log('Updated: ', POUCHDB_CSS);
});
}
Expand Down Expand Up @@ -67,7 +65,7 @@ function onError(err) {
}

function buildEverything() {
return bluebird.resolve()
return Promise.resolve()
.then(checkJekyll)
.then(buildCSS)
.then(buildJekyll)
Expand Down
2 changes: 1 addition & 1 deletion bin/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'use strict';

var fs = require('fs');
var Promise = require('bluebird');
var Promise = require('lie');
var through = require('through2');
var _derequire = require('derequire');
var watchify = require('watchify');
Expand Down
4 changes: 2 additions & 2 deletions docs/_guides/async-code.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ db.get('charlie').then(function (charlie) {
Promises in PouchDB
-------

Promises are supported natively in [some browsers](http:https://caniuse.com/#feat=promises). But since they're not universally supported, PouchDB uses [lie](https://github.com/calvinmetcalf/lie) in browsers that don't support them. In Node.js PouchDB uses [bluebird](https://github.com/petkaantonov/bluebird).
Promises are supported natively in [some browsers](http:https://caniuse.com/#feat=promises). But since they're not universally supported, PouchDB uses [lie](https://github.com/calvinmetcalf/lie) in browsers and Node.js when they are not supported.

You are free to integrate any Promise library you like with PouchDB, as long as it is compliant with [the Promises A+ spec](http:https://promisesaplus.com/). Some libraries that fit the bill:

Expand All @@ -224,4 +224,4 @@ If you use one of these libraries, then you will have access to some advanced Pr
Next
------

Now that you have a grasp on promises, let's learn about updating and deleting documents.
Now that you have a grasp on promises, let's learn about updating and deleting documents.
5 changes: 2 additions & 3 deletions docs/_includes/api/api_overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

… where the `error` will be undefined if there's no error.

If you don't specify a `callback`, then the API returns a [promise][]. In [supported browsers](http:https://caniuse.com/#feat=promises), native promises are used, falling back to the minimal library [lie][] as needed. In Node.js, promises come from [Bluebird][].
If you don't specify a `callback`, then the API returns a [promise][]. In [supported browsers](http:https://caniuse.com/#feat=promises) or Node.js, native promises are used, falling back to the minimal library [lie][] as needed.

{% include alert/start.html variant="info"%}
{% markdown %}
Expand All @@ -32,5 +32,4 @@

[promise]: https://www.promisejs.org/
[lie]: https://github.com/calvinmetcalf/lie
[bluebird]: https://github.com/petkaantonov/bluebird
[event emitter]: http:https://nodejs.org/api/events.html#events_class_events_eventemitter
[event emitter]: http:https://nodejs.org/api/events.html#events_class_events_eventemitter
4 changes: 2 additions & 2 deletions docs/_includes/api/extras.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@
var Promise = require('pouchdb/extras/promise');
{% endhighlight %}

The ES6 `Promise` shim as used by PouchDB. Expect this to be `bluebird` in Node, `lie` in browsers without Promise support, and the global `Promise` in browsers with Promise support.
The ES6 `Promise` shim as used by PouchDB. Expect this to be `lie` where a global `Promise` does not exist, the global `Promise` is used when supported.

#### Caveats

These APIs are not rigorously documented and may change frequently. Refer to the [source code](https://github.com/pouchdb/pouchdb/tree/master/extras) for the details of the APIs.

If your plugin depends on a particular version of PouchDB, please notify your users. Unless you like to live dangerously, you should also nail down the version of PouchDB you are using in your `package.json`. And if you need any other internal modules, please submit a pull request!
If your plugin depends on a particular version of PouchDB, please notify your users. Unless you like to live dangerously, you should also nail down the version of PouchDB you are using in your `package.json`. And if you need any other internal modules, please submit a pull request!
4 changes: 2 additions & 2 deletions lib/deps/promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
if (typeof Promise === 'function') {
module.exports = Promise;
} else {
module.exports = require('bluebird');
}
module.exports = require('lie');
}
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
],
"dependencies": {
"argsarray": "0.0.1",
"bluebird": "^1.2.4",
"debug": "^2.1.2",
"double-ended-queue": "^2.0.0-0",
"es3ify": "^0.1.3",
Expand Down Expand Up @@ -113,7 +112,6 @@
"./lib/adapters/preferredAdapters.js": "./lib/adapters/preferredAdapters-browser.js",
"./lib/deps/binary/buffer.js": "./lib/deps/binary/buffer-browser.js",
"./lib/deps/migrate.js": "./lib/deps/migrate-browser.js",
"bluebird": "lie",
"fs": false,
"leveldown": false
}
Expand Down
3 changes: 0 additions & 3 deletions tests/component/test.headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
var http = require('http');
var PouchDB = require('../../lib');
var should = require("chai").should();
require('bluebird').onPossiblyUnhandledRejection(function (e, promise) {
throw e;
});

describe('test.headers.js', function () {

Expand Down
3 changes: 0 additions & 3 deletions tests/integration/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,6 @@ if (typeof module !== 'undefined' && module.exports) {
testDir = testDir.slice(-1) === '/' ? testDir : testDir + '/';
global.PouchDB.prefix = testDir + global.PouchDB.prefix;
require('../../lib/adapters/leveldb').use_prefix = true;
require('bluebird').onPossiblyUnhandledRejection(function (e, promise) {
throw e;
});
}
module.exports = testUtils;
}
4 changes: 1 addition & 3 deletions tests/performance/perf.attachments.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ function randomBlob(size) {

module.exports = function (PouchDB, opts) {

// need to use bluebird for promises everywhere, so we're comparing
// apples to apples
require('bluebird'); // var Promise = require('bluebird');
require('lie');
var utils = require('./utils');

var testCases = [
Expand Down
2 changes: 1 addition & 1 deletion tests/performance/perf.basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module.exports = function (PouchDB, opts) {

var Promise = require('bluebird');
var Promise = require('lie');
var utils = require('./utils');
var commonUtils = require('../common-utils.js');

Expand Down
4 changes: 1 addition & 3 deletions tests/performance/perf.views.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

module.exports = function (PouchDB, opts) {

// need to use bluebird for promises everywhere, so we're comparing
// apples to apples
var Promise = require('bluebird');
var Promise = require('lie');
var utils = require('./utils');

function makeTestDocs() {
Expand Down
2 changes: 1 addition & 1 deletion tests/performance/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
var reporter = require('./perf.reporter');
var test = require('tape');
var commonUtils = require('../common-utils.js');
var Promise = require('bluebird');
var Promise = require('lie');

var grep;
if (global.window && global.window.location && global.window.location.search) {
Expand Down

0 comments on commit 72f1f0d

Please sign in to comment.